on develop help sign in
Line wrapping: Add some internal comments to displayLines
commit6eb5ef3f066e9b21e51f42af582b9e1bb934891c authorAli Abrar <aliabrar@gmail.com> dateSun 4 Nov 2018, 14:02 (8 years ago) parent4a9af8e
1 file changed+12−2
src/Data/Text/Zipper.hs+12−2
src/Data/Text/Zipper.hs+12−2
@@ -162,10 +162,11 @@ displayLines
162162 -> TextZipper -- ^ The text input contents and cursor state
163163 -> DisplayLines tag
164164displayLines width tag cursorTag (TextZipper lb b a la) =
165− let linesBefore :: [[Text]]
165+ let linesBefore :: [[Text]] -- The wrapped lines before the cursor line
166166 linesBefore = map (wrapWithOffset width 0) $ reverse lb
167− linesAfter :: [[Text]]
167+ linesAfter :: [[Text]] -- The wrapped lines after the cursor line
168168 linesAfter = map (wrapWithOffset width 0) la
169+ offsets :: Map Int Int
169170 offsets = offsetMap $ mconcat
170171 [ linesBefore
171172 , [wrapWithOffset width 0 $ b <> a]
@@ -173,10 +174,19 @@ displayLines width tag cursorTag (TextZipper lb b a la) =
173174 ]
174175 spansBefore = map ((:[]) . Span tag) $ concat linesBefore
175176 spansAfter = map ((:[]) . Span tag) $ concat linesAfter
177+ -- Separate the spans before the cursor into
178+ -- * spans that are on earlier display lines (though on the same logical line), and
179+ -- * spans that are on the same display line
176180 (spansCurrentBefore, spansCurLineBefore) = fromMaybe ([], []) $
177181 initLast $ map ((:[]) . Span tag) (wrapWithOffset width 0 b)
182+ -- Calculate the number of columns on the cursor's display line before the cursor
178183 curLineOffset = spansLength spansCurLineBefore
184+ -- Check whether the spans on the current display line are long enough that
185+ -- the cursor has to go to the next line
179186 cursorAfterEOL = curLineOffset == width
187+ -- Separate the span after the cursor into
188+ -- * spans that are on the same display line, and
189+ -- * spans that are on later display lines (though on the same logical line)
180190 (spansCurLineAfter, spansCurrentAfter) = fromMaybe ([], []) $
181191 headTail $ case T.uncons a of
182192 Nothing -> [[Span cursorTag " "]]