Scroll so editor cursor is always visible
This took a bit to figure out. Also, this is the only point in this project where I use lenses.
This commit is contained in:
parent
70bbc3a69a
commit
ae28d79b46
2 changed files with 8 additions and 1 deletions
|
|
@ -18,6 +18,7 @@ dependencies:
|
||||||
- async
|
- async
|
||||||
- brick
|
- brick
|
||||||
- containers
|
- containers
|
||||||
|
- microlens
|
||||||
- optparse-applicative
|
- optparse-applicative
|
||||||
- text
|
- text
|
||||||
- text-zipper
|
- text-zipper
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import Brick.Widgets.Edit
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text.Zipper
|
import Data.Text.Zipper
|
||||||
import qualified Graphics.Vty as Vty
|
import qualified Graphics.Vty as Vty
|
||||||
|
import Lens.Micro
|
||||||
|
|
||||||
import Forest.Client.ResourceName
|
import Forest.Client.ResourceName
|
||||||
|
|
||||||
|
|
@ -52,8 +53,13 @@ handleNodeEditorEvent event ne = do
|
||||||
pure ne{neEditor = newEditor}
|
pure ne{neEditor = newEditor}
|
||||||
|
|
||||||
renderNodeEditor :: NodeEditor -> Widget ResourceName
|
renderNodeEditor :: NodeEditor -> Widget ResourceName
|
||||||
renderNodeEditor ne = vLimit height $ renderEditor renderFunc True $ neEditor ne
|
renderNodeEditor ne = makeVisible $ vLimit height $ renderEditor renderFunc True ed
|
||||||
where
|
where
|
||||||
|
ed = neEditor ne
|
||||||
|
|
||||||
height = length $ getCurrentText ne
|
height = length $ getCurrentText ne
|
||||||
renderFunc :: [T.Text] -> Widget ResourceName
|
renderFunc :: [T.Text] -> Widget ResourceName
|
||||||
renderFunc = vBox . map (\t -> if T.null t then txt " " else txt t)
|
renderFunc = vBox . map (\t -> if T.null t then txt " " else txt t)
|
||||||
|
|
||||||
|
(row, col) = cursorPosition $ ed ^. editContentsL
|
||||||
|
makeVisible = visibleRegion (Location (col, row)) (1, 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue