From 8698333f5bfc8fb8be62e7e1c93cae689a9f602f Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 11 Sep 2025 23:43:09 +0100 Subject: [PATCH] refactor to make sure that we count the visual scroll column on move/delete, in normal mode --- fcore/normal-mode/make-normal-delete.sml | 12 ++- fcore/normal-mode/normal-finish.sml | 40 +++++++--- fcore/normal-mode/normal-mode-with.sml | 10 ++- fcore/normal-mode/normal-move.sml | 96 ++++++++++-------------- 4 files changed, 83 insertions(+), 75 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index f137fbf..991d3ae 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -400,6 +400,7 @@ struct val cursorIdx = 0 val startLine = 0 + val visualScrollColumn = 0 val buffer = LineGap.goToIdx (cursorIdx, buffer) val drawMsg = TextBuilder.build @@ -416,7 +417,16 @@ struct val mode = NORMAL_MODE "" in NormalModeWith.bufferAndCursorIdx - (app, buffer, cursorIdx, mode, startLine, searchList, drawMsg, time) + ( app + , buffer + , cursorIdx + , mode + , startLine + , searchList + , drawMsg + , time + , visualScrollColumn + ) end fun helpDeleteToMatch (app: app_type, low, high, time) = diff --git a/fcore/normal-mode/normal-finish.sml b/fcore/normal-mode/normal-finish.sml index 95dd165..7c2a930 100644 --- a/fcore/normal-mode/normal-finish.sml +++ b/fcore/normal-mode/normal-finish.sml @@ -16,7 +16,8 @@ struct (* calculate scroll column *) val buffer = LineGap.goToIdx (cursorIdx, buffer) - val visualScrollColumn = TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) (* move LineGap to first line displayed on screen *) val buffer = LineGap.goToLine (startLine, buffer) @@ -50,6 +51,7 @@ struct , searchList , msgs , bufferModifyTime + , visualScrollColumn ) end @@ -84,7 +86,10 @@ struct , ... } = app - val newBuffer = LineGap.goToLine (startLine, buffer) + val newBuffer = LineGap.goToIdx (cursorIdx, buffer) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) + val newBuffer = LineGap.goToLine (startLine, newBuffer) val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer) val drawMsg = TextBuilder.build @@ -106,6 +111,7 @@ struct , searchList , drawMsg , bufferModifyTime + , visualScrollColumn ) end @@ -119,6 +125,10 @@ struct let val {windowWidth, windowHeight, startLine, searchString, ...} = app + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) + (* move LineGap to first line displayed on screen *) val buffer = LineGap.goToLine (startLine, buffer) @@ -152,6 +162,7 @@ struct , searchList , drawMsg , bufferModifyTime + , visualScrollColumn ) end @@ -187,15 +198,20 @@ struct , [] ) in - NormalModeWith.bufferAndCursorIdx - ( app - , buffer - , cursorIdx - , NORMAL_MODE "" - , startLine - , searchList - , drawMsg - , bufferModifyTime - ) + let + val _ = raise Fail "centering to line is unimplemented\n" + in + NormalModeWith.bufferAndCursorIdx + ( app + , buffer + , cursorIdx + , NORMAL_MODE "" + , startLine + , searchList + , drawMsg + , bufferModifyTime + , #visualScrollColumn app + ) + end end end diff --git a/fcore/normal-mode/normal-mode-with.sml b/fcore/normal-mode/normal-mode-with.sml index 35ccadb..7646245 100644 --- a/fcore/normal-mode/normal-mode-with.sml +++ b/fcore/normal-mode/normal-mode-with.sml @@ -10,6 +10,7 @@ struct , newSearchList , newMsgs , newBufferModifyTime + , newVisualScrollColumn ) = let val @@ -19,11 +20,11 @@ struct , windowWidth = _ , windowHeight = _ , searchList = _ + , visualScrollColumn = _ , msgs = _ , searchString , startLine , cursorIdx - , visualScrollColumn } = app in { mode = mode @@ -32,11 +33,11 @@ struct , windowWidth = newWidth , windowHeight = newHeight , searchList = newSearchList + , visualScrollColumn = newVisualScrollColumn , msgs = newMsgs , searchString = searchString , startLine = startLine , cursorIdx = cursorIdx - , visualScrollColumn = visualScrollColumn } end @@ -49,6 +50,7 @@ struct , newSearchList , newMsgs , newBufferModifyTime + , newVisualScrollColumn ) = let val @@ -58,11 +60,11 @@ struct , cursorIdx = _ , startLine = _ , searchList = _ + , visualScrollColumn = _ , msgs = _ , searchString , windowWidth , windowHeight - , visualScrollColumn } = app in { mode = newMode @@ -71,11 +73,11 @@ struct , cursorIdx = newCursorIdx , startLine = newStartLine , searchList = newSearchList + , visualScrollColumn = newVisualScrollColumn , msgs = newMsgs , searchString = searchString , windowWidth = windowWidth , windowHeight = windowHeight - , visualScrollColumn = visualScrollColumn } end diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 2f76600..76321c1 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -40,6 +40,7 @@ struct , searchList , drawMsg , bufferModifyTime + , 0 ) end @@ -63,6 +64,8 @@ struct val bufferLine = bufferLine - 1 val buffer = LineGap.goToIdx (bufferIdx, buffer) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, bufferIdx, windowWidth) val bufferLine = let val maxHeight = windowHeight - TextConstants.ySpace @@ -96,6 +99,7 @@ struct , searchList , drawMsg , bufferModifyTime + , visualScrollColumn ) end @@ -120,6 +124,8 @@ struct val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine) val buffer = LineGap.goToIdx (cursorIdx, buffer) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) val startLine = TextWindow.getStartLineWithCursorCentered (buffer, cursorIdx, origLine, windowWidth, windowHeight div 2) @@ -148,6 +154,7 @@ struct , searchList , drawMsg , bufferModifyTime + , visualScrollColumn ) end @@ -172,66 +179,39 @@ struct val buffer = LineGap.goToLine (startLine, buffer) val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer) in - if - TextWindow.isCursorVisible - (buffer, cursorIdx, startLine, windowWidth, windowHeight) - then - (* if visible, just need to redraw; no need to get line *) - let - val drawMsg = TextBuilder.build - ( startLine - , cursorIdx - , buffer - , windowWidth - , windowHeight - , searchList - , searchString - , [] - ) - in - NormalModeWith.bufferAndCursorIdx - ( app - , buffer - , cursorIdx - , NORMAL_MODE "" - , startLine - , searchList - , drawMsg - , bufferModifyTime - ) - end - else - (* not visible, so need to get startLine where cursor is visible *) - let - val buffer = LineGap.goToIdx (cursorIdx, buffer) - val startLine = TextWindow.getStartLineWithCursorCentered - (buffer, cursorIdx, startLine, windowWidth, windowHeight div 2) + let + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val visualScrollColumn = + TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) + val startLine = TextWindow.getStartLineWithCursorCentered + (buffer, cursorIdx, startLine, windowWidth, windowHeight div 2) - val buffer = LineGap.goToLine (startLine, buffer) - val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer) + val buffer = LineGap.goToLine (startLine, buffer) + val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer) - val drawMsg = TextBuilder.build - ( startLine - , cursorIdx - , buffer - , windowWidth - , windowHeight - , searchList - , searchString - , [] - ) - in - NormalModeWith.bufferAndCursorIdx - ( app - , buffer - , cursorIdx - , NORMAL_MODE "" - , startLine - , searchList - , drawMsg - , bufferModifyTime - ) - end + val drawMsg = TextBuilder.build + ( startLine + , cursorIdx + , buffer + , windowWidth + , windowHeight + , searchList + , searchString + , [] + ) + in + NormalModeWith.bufferAndCursorIdx + ( app + , buffer + , cursorIdx + , NORMAL_MODE "" + , startLine + , searchList + , drawMsg + , bufferModifyTime + , visualScrollColumn + ) + end end fun firstNonSpaceChr (app: app_type) =