complete implementation of rightwards navigation (viL)
This commit is contained in:
@@ -21,27 +21,18 @@ struct
|
|||||||
|
|
||||||
fun moveRight (app: app_type) =
|
fun moveRight (app: app_type) =
|
||||||
let
|
let
|
||||||
(* todo: proper implementation of moveRight
|
|
||||||
* currently, we also retrieve the newCursorIdx improperly.
|
|
||||||
* To do it properly, we have to look inside LineGap
|
|
||||||
* instead of just incrementing cursorIdx by 1.
|
|
||||||
* So:
|
|
||||||
* - Find newCursorIdx from LineGap
|
|
||||||
* *)
|
|
||||||
|
|
||||||
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
||||||
|
|
||||||
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
||||||
val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
(* todo: call to retrieve newCursorIdx should be below *)
|
val cursorIdx = Cursor.viL (buffer, cursorIdx)
|
||||||
val newCursorIdx = cursorIdx + 1
|
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen, and build new text *)
|
(* move LineGap to first line displayed on screen, and build new text *)
|
||||||
val newBuffer = LineGap.goToLine (startLine, newBuffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
(startLine, cursorIdx, newBuffer, windowWidth, windowHeight)
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx (app, newBuffer, newCursorIdx)
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
||||||
in
|
in
|
||||||
(newApp, drawMsg)
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
|
|||||||
30
fcore/cursor.sml
Normal file
30
fcore/cursor.sml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
structure Cursor =
|
||||||
|
struct
|
||||||
|
(* Prerequisite: lineGap is moved to requested idx first *)
|
||||||
|
fun viL (lineGap: LineGap.t, cursorIdx) =
|
||||||
|
let
|
||||||
|
val {rightStrings, idx = bufferIdx, ...} = lineGap
|
||||||
|
in
|
||||||
|
case rightStrings of
|
||||||
|
hd :: tl =>
|
||||||
|
let
|
||||||
|
(* idx relative to this string *)
|
||||||
|
val strIdx = cursorIdx - bufferIdx
|
||||||
|
in
|
||||||
|
if strIdx < String.size hd - 2 then
|
||||||
|
(* increment if there is a character after where cursor is *)
|
||||||
|
cursorIdx + 1
|
||||||
|
else
|
||||||
|
(case tl of
|
||||||
|
_ :: _ =>
|
||||||
|
(* if there is another string after current head, we can increment cursorIdx *)
|
||||||
|
bufferIdx + String.size hd - 1
|
||||||
|
| _ =>
|
||||||
|
(* if there is no string after current head, return original cursorIdx *)
|
||||||
|
cursorIdx)
|
||||||
|
end
|
||||||
|
| [] =>
|
||||||
|
(* return original cursorIdx if there is nothing to the right *)
|
||||||
|
cursorIdx
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -44,7 +44,7 @@ struct
|
|||||||
val _ = Gles3.loadGlad ()
|
val _ = Gles3.loadGlad ()
|
||||||
|
|
||||||
(* load file intol gap buffer and create initial app *)
|
(* load file intol gap buffer and create initial app *)
|
||||||
val io = TextIO.openIn "fcore/text-builder.sml"
|
val io = TextIO.openIn "temp.txt"
|
||||||
val lineGap = ioToLineGap (io, LineGap.empty)
|
val lineGap = ioToLineGap (io, LineGap.empty)
|
||||||
val _ = TextIO.closeIn io
|
val _ = TextIO.closeIn io
|
||||||
val app = AppType.init (lineGap, 1920, 1080)
|
val app = AppType.init (lineGap, 1920, 1080)
|
||||||
|
|||||||
1
shf.mlb
1
shf.mlb
@@ -16,6 +16,7 @@ ann
|
|||||||
in
|
in
|
||||||
fcore/text-builder.sml
|
fcore/text-builder.sml
|
||||||
end
|
end
|
||||||
|
fcore/cursor.sml
|
||||||
fcore/app-update.sml
|
fcore/app-update.sml
|
||||||
|
|
||||||
(* IMPERATIVE SHELL *)
|
(* IMPERATIVE SHELL *)
|
||||||
|
|||||||
Reference in New Issue
Block a user