From b396a1b36bf7e527f2566fa701366f65800b1f0b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 5 Nov 2024 19:50:36 +0000 Subject: [PATCH] minor fix in Cursor.viH: if strIdx is not in hd of rightStrings, check tl of rightStrings --- fcore/cursor.sml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fcore/cursor.sml b/fcore/cursor.sml index df94227..a132fea 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -244,33 +244,30 @@ struct cursorIdx - 1 | [] => 0) - (* Prerequisite: lineGap is moved to requested idx first - * Implementation is mostly the same as the viL function, - * except we focus on decrementing instead, - * and we examing leftStrings list instead of tail of rightStrings - * if head of rightStrings is empty or does not have the idx we want. - * todo: check if we are in a \r\n pair, but this is not a priority *) + (* Prerequisite: lineGap is moved to requested idx first. *) fun viH (lineGap: LineGap.t, cursorIdx) = let val {rightStrings, leftStrings, idx = bufferIdx, ...} = lineGap in case rightStrings of - hd :: _ => + hd :: tl => let (* convert absolute cursorIdx to idx relative to hd string *) val strIdx = cursorIdx - bufferIdx in if strIdx < String.size hd then + (* strIdx in hd *) helpViH (strIdx, hd, cursorIdx, leftStrings) else - (case leftStrings of - lhd :: ltl => + (* strIdx in tl *) + (case tl of + tlhd :: tltl => let val strIdx = strIdx - String.size hd in - helpViH (strIdx, lhd, cursorIdx, ltl) + helpViH (strIdx, tllhd, cursorIdx, hd :: leftStrings) end - | [] => 0) + | [] => cursorIdx) end | [] => cursorIdx end