Skip to content

Commit 3cb010a

Browse files
committed
Add text wrapping in note view
1 parent bd6e4e7 commit 3cb010a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

ff-brick/Main.hs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Brick (
1212
Direction (Down, Up),
1313
HScrollBarOrientation (OnBottom),
1414
VScrollBarOrientation (OnRight),
15-
ViewportType (Both),
15+
ViewportType (Vertical),
1616
attrMap,
1717
attrName,
1818
defaultMain,
@@ -22,6 +22,7 @@ import Brick (
2222
neverShowCursor,
2323
on,
2424
txt,
25+
txtWrap,
2526
vScrollBy,
2627
vScrollPage,
2728
vScrollToBeginning,
@@ -174,20 +175,17 @@ appDraw Model{visibleNotes, isNoteOpen} = [mainWidget <=> keysHelpLine]
174175

175176
openNoteWidget =
176177
border
177-
( viewport
178-
OpenNoteViewport
179-
Both
180-
(txt {- TODO txtWrap? -} content)
178+
( viewport OpenNoteViewport Vertical (txtWrap openNoteContent)
181179
& withHScrollBars OnBottom
182180
& withVScrollBars OnRight
183181
)
184182
& withVisibleBorderIf isNoteOpen
185-
where
186-
content =
187-
case listSelectedElement visibleNotes of
188-
Nothing -> ""
189-
Just (_, Entity{entityVal = Note{note_text}}) ->
190-
Text.pack $ filter (/= '\r') $ fromRgaM note_text
183+
184+
openNoteContent =
185+
case listSelectedElement visibleNotes of
186+
Nothing -> ""
187+
Just (_, Entity _ note) ->
188+
Text.pack $ clean $ fromRgaM note.note_text
191189

192190
keysHelpLine =
193191
hBox
@@ -206,6 +204,10 @@ appDraw Model{visibleNotes, isNoteOpen} = [mainWidget <=> keysHelpLine]
206204
, txt " open"
207205
]
208206

207+
-- Clean string for Brick
208+
clean :: String -> String
209+
clean = filter (/= '\r')
210+
209211
highlightAttr :: AttrName
210212
highlightAttr = attrName "highlight"
211213

@@ -248,7 +250,7 @@ handleViewportEvent = \case
248250
vps = viewportScroll OpenNoteViewport
249251

250252
renderListItem :: Bool -> EntityDoc Note -> Widget
251-
renderListItem _isSelected Entity{entityVal} = txt $ noteTitle entityVal
253+
renderListItem _isSelected (Entity _ note) = txt $ noteTitle note
252254

253255
noteTitle :: Note -> Text
254256
noteTitle Note{note_text} =

0 commit comments

Comments
 (0)