@@ -162,10 +162,11 @@ displayLines
162 -> TextZipper -- ^ The text input contents and cursor state
162 -> TextZipper -- ^ The text input contents and cursor state
163 -> DisplayLines tag
163 -> DisplayLines tag
164displayLines width tag cursorTag (TextZipper lb b a la) =
164displayLines width tag cursorTag (TextZipper lb b a la) =
165− let linesBefore :: [[Text]]
165+ let linesBefore :: [[Text]] -- The wrapped lines before the cursor line
166 linesBefore = map (wrapWithOffset width 0) $ reverse lb
166 linesBefore = map (wrapWithOffset width 0) $ reverse lb
167− linesAfter :: [[Text]]
167+ linesAfter :: [[Text]] -- The wrapped lines after the cursor line
168 linesAfter = map (wrapWithOffset width 0) la
168 linesAfter = map (wrapWithOffset width 0) la
169+ offsets :: Map Int Int
169 offsets = offsetMap $ mconcat
170 offsets = offsetMap $ mconcat
170 [ linesBefore
171 [ linesBefore
171 , [wrapWithOffset width 0 $ b <> a]
172 , [wrapWithOffset width 0 $ b <> a]
@@ -173,10 +174,19 @@ displayLines width tag cursorTag (TextZipper lb b a la) =
174 spansBefore = map ((:[]) . Span tag) $ concat linesBefore
175 spansBefore = map ((:[]) . Span tag) $ concat linesBefore
175 spansAfter = map ((:[]) . Span tag) $ concat linesAfter
176 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
176 (spansCurrentBefore, spansCurLineBefore) = fromMaybe ([], []) $
180 (spansCurrentBefore, spansCurLineBefore) = fromMaybe ([], []) $
177 initLast $ map ((:[]) . Span tag) (wrapWithOffset width 0 b)
181 initLast $ map ((:[]) . Span tag) (wrapWithOffset width 0 b)
182+ -- Calculate the number of columns on the cursor's display line before the cursor
178 curLineOffset = spansLength spansCurLineBefore
183 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
179 cursorAfterEOL = curLineOffset == width
186 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)
180 (spansCurLineAfter, spansCurrentAfter) = fromMaybe ([], []) $
190 (spansCurLineAfter, spansCurrentAfter) = fromMaybe ([], []) $
181 headTail $ case T.uncons a of
191 headTail $ case T.uncons a of
182 Nothing -> [[Span cursorTag " "]]
192 Nothing -> [[Span cursorTag " "]]