From b9e2da3ff9fbcc54efd72cd7b52a6c9d0af053fb Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 13 Sep 2025 00:02:44 +0100 Subject: [PATCH] add function to skip to first visible column in TextBuilderWithCursor (sometimes the function is buggy, which I need to fix) --- .../text-builder/text-builder-with-cursor.sml | 109 +++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/fcore/text-builder/text-builder-with-cursor.sml b/fcore/text-builder/text-builder-with-cursor.sml index 935092a..efdd5bb 100644 --- a/fcore/text-builder/text-builder-with-cursor.sml +++ b/fcore/text-builder/text-builder-with-cursor.sml @@ -45,7 +45,7 @@ struct ) | (_, _) => acc - and skipToColumnStart + and skipToNextLine (pos, str, stl, line, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc) = if Vector.length line = 0 then let @@ -96,6 +96,96 @@ struct end end + and skipToFirstVisibleColumn + ( pos + , str + , stl + , line + , ltl + , posY + , column + , lineNumber + , absIdx + , cursorIdx + , env: Utils.env_data + , acc + ) = + if column = #scrollColumnStart env then + (* return to build function *) + build + ( pos + , str + , stl + , line + , ltl + , #startX env + , posY + , column + , lineNumber + , absIdx + , cursorIdx + , env + , acc + ) + else if pos = String.size str then + (* go to next node *) + case (stl, ltl) of + (shd :: stl, lhd :: ltl) => + skipToFirstVisibleColumn + ( 0 + , shd + , stl + , lhd + , ltl + , posY + , column + , lineNumber + , absIdx + , cursorIdx + , env + , acc + ) + | (_, _) => acc + else + case String.sub (str, pos) of + #"\n" => + let + (* increment line lineNumber and posY, and then call build function *) + val posY = posY + TC.ySpace + val lineNumber = lineNumber + 1 + in + build + ( pos + 1 + , str + , stl + , line + , ltl + , #startX env + , posY + , #scrollColumnStart env + , lineNumber + , absIdx + 1 + , cursorIdx + , env + , acc + ) + end + | chr => + skipToFirstVisibleColumn + ( pos + 1 + , str + , stl + , line + , ltl + , posY + , column + 1 + , lineNumber + , absIdx + 1 + , cursorIdx + , env + , acc + ) + and build ( pos , str @@ -131,7 +221,22 @@ struct ) | (_, _) => acc else if column < #scrollColumnStart env then - skipToColumnStart + skipToFirstVisibleColumn + ( pos + , str + , stl + , line + , ltl + , posY + , column + , lineNumber + , absIdx + , cursorIdx + , env + , acc + ) + else if column > #scrollColumnEnd env then + skipToNextLine ( pos , str , stl