fix bugs in implementing and using text buffer. Some functions did not save the drawMsg to the app's state, which we means we didn't draw in those cases. The text builder functions also drew cursors on characters even when the cursor is not at this position. Both of these bugs are fixed.

This commit is contained in:
2025-09-12 23:21:53 +01:00
parent 77a64ae794
commit 422d6ad9ac
6 changed files with 14 additions and 16 deletions

View File

@@ -520,8 +520,8 @@ struct
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val low = Cursor.prevWordStrict (buffer, cursorIdx, 1) val low = Cursor.prevWORDStrict (buffer, cursorIdx, 1)
val high = Cursor.endOfWordStrict (buffer, cursorIdx, 1) + 1 val high = Cursor.endOfWORDStrict (buffer, cursorIdx, 1) + 1
val buffer = LineGap.goToIdx (high, buffer) val buffer = LineGap.goToIdx (high, buffer)
val length = high - low val length = high - low

View File

@@ -41,7 +41,7 @@ struct
) )
val drawMsg = Vector.concat drawMsg val drawMsg = Vector.concat drawMsg
val drawMsg = DRAW_TEXT drawMsg val drawMsg = DRAW_TEXT drawMsg
val drawMsg = [DRAW drawMsg] val msgs = DRAW drawMsg :: msgs
val mode = NORMAL_MODE "" val mode = NORMAL_MODE ""
in in
@@ -91,7 +91,7 @@ struct
val newBuffer = LineGap.goToIdx (cursorIdx, buffer) val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
val visualScrollColumn = val visualScrollColumn =
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) TextScroll.getScrollColumn (buffer, cursorIdx, newWidth)
val newBuffer = LineGap.goToLine (startLine, newBuffer) val newBuffer = LineGap.goToLine (startLine, newBuffer)
val lineIdx = TextBuilderUtils.getLineAbsIdxFromBuffer (startLine, buffer) val lineIdx = TextBuilderUtils.getLineAbsIdxFromBuffer (startLine, buffer)
@@ -99,15 +99,15 @@ struct
( startLine ( startLine
, cursorIdx , cursorIdx
, buffer , buffer
, windowWidth , newWidth
, windowHeight , newHeight
, searchList , searchList
, searchString , searchString
, visualScrollColumn , visualScrollColumn
) )
val drawMsg = Vector.concat drawMsg val drawMsg = Vector.concat drawMsg
val drawMsg = DRAW_TEXT drawMsg val drawMsg = DRAW_TEXT drawMsg
val drawMsg = [DRAW drawMsg] val msgs = [DRAW drawMsg]
in in
NormalModeWith.bufferAndSize NormalModeWith.bufferAndSize
( app ( app
@@ -115,7 +115,7 @@ struct
, newWidth , newWidth
, newHeight , newHeight
, searchList , searchList
, drawMsg , msgs
, bufferModifyTime , bufferModifyTime
, visualScrollColumn , visualScrollColumn
) )
@@ -159,7 +159,7 @@ struct
) )
val drawMsg = Vector.concat drawMsg val drawMsg = Vector.concat drawMsg
val drawMsg = DRAW_TEXT drawMsg val drawMsg = DRAW_TEXT drawMsg
val drawMsg = [DRAW drawMsg] val msgs = DRAW drawMsg :: initialMsg
val mode = NORMAL_MODE "" val mode = NORMAL_MODE ""
in in
@@ -170,7 +170,7 @@ struct
, mode , mode
, startLine , startLine
, searchList , searchList
, drawMsg , msgs
, bufferModifyTime , bufferModifyTime
, visualScrollColumn , visualScrollColumn
) )

View File

@@ -84,7 +84,7 @@ struct
val drawMsg = NormalModeTextBuilder.build val drawMsg = NormalModeTextBuilder.build
( bufferLine ( bufferLine
, lineIdx , bufferIdx
, buffer , buffer
, windowWidth , windowWidth
, windowHeight , windowHeight

View File

@@ -27,7 +27,6 @@ struct
(* get relative index of line to start building from *) (* get relative index of line to start building from *)
val strPos = val strPos =
Utils.getRelativeLineStartFromRightHead (startLine, curLine, lhd) Utils.getRelativeLineStartFromRightHead (startLine, curLine, lhd)
+ 1
(* get absolute idx of line *) (* get absolute idx of line *)
val absIdx = curIdx + strPos val absIdx = curIdx + strPos
val searchPos = BinSearch.equalOrMore (absIdx, searchList) val searchPos = BinSearch.equalOrMore (absIdx, searchList)

View File

@@ -207,8 +207,7 @@ struct
in Utils.makeCursorOnChr (chr, posX, posY, env) :: acc in Utils.makeCursorOnChr (chr, posX, posY, env) :: acc
end end
else else
Utils.makeChr (chr, posX, posY, env) Utils.makeChr (chr, posX, posY, env) :: acc
:: Utils.makeCursor (posX, posY, env) :: acc
in in
build build
( pos + 1 ( pos + 1

View File

@@ -270,8 +270,8 @@ struct
let let
val acc = val acc =
if absIdx = cursorIdx then if absIdx = cursorIdx then
Utils.makeCursor (posX, posY, env) Utils.makeCursorOnChr (chr, posX, posY, env)
:: Utils.makeCursorOnChr (chr, posX, posY, env) :: acc :: Utils.makeCursor (posX, posY, env) :: acc
else if Utils.isInSearchRange (absIdx, searchPos, env) then else if Utils.isInSearchRange (absIdx, searchPos, env) then
Utils.makeHighlightChr (chr, posX, posY, env) Utils.makeHighlightChr (chr, posX, posY, env)
:: Utils.makeHighlight (posX, posY, env) :: acc :: Utils.makeHighlight (posX, posY, env) :: acc