fix 'getStartLineBefore' in text-window.sml, where we always decrement 'lineNum' variable when encountering \n, and use 'Int.max (lineNum - 1, 0)' to clip lineNum to 0 if it happens to go below 0
This commit is contained in:
@@ -2,15 +2,6 @@ structure TextWindow =
|
|||||||
struct
|
struct
|
||||||
open TextConstants
|
open TextConstants
|
||||||
|
|
||||||
fun isPrevChrLn (str, strPos, strTl) =
|
|
||||||
if strPos > 0 then
|
|
||||||
String.sub (str, strPos - 1) = #"\n"
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ =>
|
|
||||||
String.sub (hd, String.size hd - 1) = #"\n"
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun getStartLineBefore (sIdx, shd, lineNum, absIdx, cursorIdx, stl) =
|
fun getStartLineBefore (sIdx, shd, lineNum, absIdx, cursorIdx, stl) =
|
||||||
if sIdx < 0 then
|
if sIdx < 0 then
|
||||||
case stl of
|
case stl of
|
||||||
@@ -20,21 +11,15 @@ struct
|
|||||||
| [] =>
|
| [] =>
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
if absIdx <= cursorIdx then
|
if absIdx = cursorIdx then
|
||||||
lineNum
|
Int.max (lineNum - 1, 0)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val chr = String.sub (shd, sIdx)
|
val chr = String.sub (shd, sIdx)
|
||||||
in
|
in
|
||||||
if chr = #"\n" then
|
if chr = #"\n" then
|
||||||
if isPrevChrLn (shd, sIdx, stl) then
|
getStartLineBefore
|
||||||
(* \n -> \n *)
|
(sIdx - 1, shd, lineNum - 1, absIdx - 1, cursorIdx, stl)
|
||||||
getStartLineBefore
|
|
||||||
(sIdx - 1, shd, lineNum - 1, absIdx - 1, cursorIdx, stl)
|
|
||||||
else
|
|
||||||
(* graphical-chr -> \n *)
|
|
||||||
getStartLineBefore
|
|
||||||
(sIdx - 1, shd, lineNum, absIdx - 1, cursorIdx, stl)
|
|
||||||
else
|
else
|
||||||
getStartLineBefore
|
getStartLineBefore
|
||||||
(sIdx - 1, shd, lineNum, absIdx - 1, cursorIdx, stl)
|
(sIdx - 1, shd, lineNum, absIdx - 1, cursorIdx, stl)
|
||||||
|
|||||||
Reference in New Issue
Block a user