fix exception when the buffer is empty
This commit is contained in:
@@ -19,20 +19,14 @@ struct
|
|||||||
, acc
|
, acc
|
||||||
) =
|
) =
|
||||||
let
|
let
|
||||||
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = buffer
|
val
|
||||||
in
|
{ rightStrings
|
||||||
case (rightStrings, rightLines) of
|
, rightLines
|
||||||
(shd :: stl, lhd :: ltl) =>
|
, line = curLine
|
||||||
let
|
, idx = curIdx
|
||||||
(* get relative index of line to start building from *)
|
, textLength
|
||||||
val strPos =
|
, ...
|
||||||
Utils.getRelativeLineStartFromRightHead (startLine, curLine, lhd)
|
} = buffer
|
||||||
(* get absolute idx of line *)
|
|
||||||
val absIdx = curIdx + strPos
|
|
||||||
|
|
||||||
val searchPos = BinSearch.equalOrMore (absIdx, searchList)
|
|
||||||
val searchPos =
|
|
||||||
if searchPos = ~1 then Vector.length searchList else searchPos
|
|
||||||
|
|
||||||
val env = Utils.initEnv
|
val env = Utils.initEnv
|
||||||
( 5
|
( 5
|
||||||
@@ -47,6 +41,29 @@ struct
|
|||||||
, startLine
|
, startLine
|
||||||
)
|
)
|
||||||
val {startX, startY, ...} = env
|
val {startX, startY, ...} = env
|
||||||
|
in
|
||||||
|
if textLength = 1 then
|
||||||
|
(* empty string, so there is nothing we can draw
|
||||||
|
* except a cursor at the line start.
|
||||||
|
* An empty string is usually thought of to have a length of 0
|
||||||
|
* and this is true, but we always have a \n at the end of the buffer
|
||||||
|
* to respect Unix-style file endings, which we always uphold.
|
||||||
|
* So, for us, an empty string has a length of 1. *)
|
||||||
|
[Utils.makeCursor (startX, startY, env)]
|
||||||
|
else
|
||||||
|
case (rightStrings, rightLines) of
|
||||||
|
(shd :: stl, lhd :: ltl) =>
|
||||||
|
let
|
||||||
|
(* get relative index of line to start building from *)
|
||||||
|
val strPos =
|
||||||
|
Utils.getRelativeLineStartFromRightHead
|
||||||
|
(startLine, curLine, lhd)
|
||||||
|
(* get absolute idx of line *)
|
||||||
|
val absIdx = curIdx + strPos
|
||||||
|
|
||||||
|
val searchPos = BinSearch.equalOrMore (absIdx, searchList)
|
||||||
|
val searchPos =
|
||||||
|
if searchPos = ~1 then Vector.length searchList else searchPos
|
||||||
in
|
in
|
||||||
TextBuilderWithHighlight.build
|
TextBuilderWithHighlight.build
|
||||||
( strPos
|
( strPos
|
||||||
|
|||||||
@@ -49,10 +49,27 @@ struct
|
|||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
fun ioToLineGap (io, acc) =
|
local
|
||||||
|
fun loop (io, acc, lastCharWasNewline) =
|
||||||
case TextIO.inputLine io of
|
case TextIO.inputLine io of
|
||||||
SOME str => ioToLineGap (io, LineGap.append (str, acc))
|
SOME str =>
|
||||||
| NONE => LineGap.goToStart acc
|
let
|
||||||
|
val endsWithNewline =
|
||||||
|
String.size str > 0
|
||||||
|
andalso String.sub (str, String.size str - 1) = #"\n"
|
||||||
|
in
|
||||||
|
loop (io, LineGap.append (str, acc), endsWithNewline)
|
||||||
|
end
|
||||||
|
| NONE =>
|
||||||
|
if lastCharWasNewline then
|
||||||
|
LineGap.goToStart acc
|
||||||
|
else
|
||||||
|
let val acc = LineGap.append ("\n", acc)
|
||||||
|
in LineGap.goToStart acc
|
||||||
|
end
|
||||||
|
in
|
||||||
|
fun ioToLineGap (io, acc) = loop (io, acc, false)
|
||||||
|
end
|
||||||
|
|
||||||
fun main () =
|
fun main () =
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user