From 422d6ad9ac4975af04c6d19e05caf0b45bc6655f Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 12 Sep 2025 23:21:53 +0100 Subject: [PATCH] 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. --- fcore/normal-mode/make-normal-delete.sml | 4 ++-- fcore/normal-mode/normal-finish.sml | 16 ++++++++-------- fcore/normal-mode/normal-move.sml | 2 +- fcore/text-builder/normal-mode-text-builder.sml | 1 - fcore/text-builder/text-builder-with-cursor.sml | 3 +-- .../text-builder/text-builder-with-highlight.sml | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 7c73fbc..6b31e1a 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -520,8 +520,8 @@ struct val {buffer, cursorIdx, searchString, ...} = app val buffer = LineGap.goToIdx (cursorIdx, buffer) - val low = Cursor.prevWordStrict (buffer, cursorIdx, 1) - val high = Cursor.endOfWordStrict (buffer, cursorIdx, 1) + 1 + val low = Cursor.prevWORDStrict (buffer, cursorIdx, 1) + val high = Cursor.endOfWORDStrict (buffer, cursorIdx, 1) + 1 val buffer = LineGap.goToIdx (high, buffer) val length = high - low diff --git a/fcore/normal-mode/normal-finish.sml b/fcore/normal-mode/normal-finish.sml index ba9bf5f..3cd8677 100644 --- a/fcore/normal-mode/normal-finish.sml +++ b/fcore/normal-mode/normal-finish.sml @@ -41,7 +41,7 @@ struct ) val drawMsg = Vector.concat drawMsg val drawMsg = DRAW_TEXT drawMsg - val drawMsg = [DRAW drawMsg] + val msgs = DRAW drawMsg :: msgs val mode = NORMAL_MODE "" in @@ -91,7 +91,7 @@ struct val newBuffer = LineGap.goToIdx (cursorIdx, buffer) val visualScrollColumn = - TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) + TextScroll.getScrollColumn (buffer, cursorIdx, newWidth) val newBuffer = LineGap.goToLine (startLine, newBuffer) val lineIdx = TextBuilderUtils.getLineAbsIdxFromBuffer (startLine, buffer) @@ -99,15 +99,15 @@ struct ( startLine , cursorIdx , buffer - , windowWidth - , windowHeight + , newWidth + , newHeight , searchList , searchString , visualScrollColumn ) val drawMsg = Vector.concat drawMsg val drawMsg = DRAW_TEXT drawMsg - val drawMsg = [DRAW drawMsg] + val msgs = [DRAW drawMsg] in NormalModeWith.bufferAndSize ( app @@ -115,7 +115,7 @@ struct , newWidth , newHeight , searchList - , drawMsg + , msgs , bufferModifyTime , visualScrollColumn ) @@ -159,7 +159,7 @@ struct ) val drawMsg = Vector.concat drawMsg val drawMsg = DRAW_TEXT drawMsg - val drawMsg = [DRAW drawMsg] + val msgs = DRAW drawMsg :: initialMsg val mode = NORMAL_MODE "" in @@ -170,7 +170,7 @@ struct , mode , startLine , searchList - , drawMsg + , msgs , bufferModifyTime , visualScrollColumn ) diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 17f8d0e..f725a0f 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -84,7 +84,7 @@ struct val drawMsg = NormalModeTextBuilder.build ( bufferLine - , lineIdx + , bufferIdx , buffer , windowWidth , windowHeight diff --git a/fcore/text-builder/normal-mode-text-builder.sml b/fcore/text-builder/normal-mode-text-builder.sml index 2423763..9c913fa 100644 --- a/fcore/text-builder/normal-mode-text-builder.sml +++ b/fcore/text-builder/normal-mode-text-builder.sml @@ -27,7 +27,6 @@ struct (* get relative index of line to start building from *) val strPos = Utils.getRelativeLineStartFromRightHead (startLine, curLine, lhd) - + 1 (* get absolute idx of line *) val absIdx = curIdx + strPos val searchPos = BinSearch.equalOrMore (absIdx, searchList) diff --git a/fcore/text-builder/text-builder-with-cursor.sml b/fcore/text-builder/text-builder-with-cursor.sml index 2812400..935092a 100644 --- a/fcore/text-builder/text-builder-with-cursor.sml +++ b/fcore/text-builder/text-builder-with-cursor.sml @@ -207,8 +207,7 @@ struct in Utils.makeCursorOnChr (chr, posX, posY, env) :: acc end else - Utils.makeChr (chr, posX, posY, env) - :: Utils.makeCursor (posX, posY, env) :: acc + Utils.makeChr (chr, posX, posY, env) :: acc in build ( pos + 1 diff --git a/fcore/text-builder/text-builder-with-highlight.sml b/fcore/text-builder/text-builder-with-highlight.sml index 53749e4..fd99f1a 100644 --- a/fcore/text-builder/text-builder-with-highlight.sml +++ b/fcore/text-builder/text-builder-with-highlight.sml @@ -270,8 +270,8 @@ struct let val acc = if absIdx = cursorIdx then - Utils.makeCursor (posX, posY, env) - :: Utils.makeCursorOnChr (chr, posX, posY, env) :: acc + Utils.makeCursorOnChr (chr, posX, posY, env) + :: Utils.makeCursor (posX, posY, env) :: acc else if Utils.isInSearchRange (absIdx, searchPos, env) then Utils.makeHighlightChr (chr, posX, posY, env) :: Utils.makeHighlight (posX, posY, env) :: acc