in TextBuilder, forgot to build cursor when cursorIdx is over space, so now we build cursor when cursorIdx is over space
This commit is contained in:
@@ -19,14 +19,38 @@ struct
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
|
||||
fun handleChr (app, chr) =
|
||||
fun moveRight (app: app_type) =
|
||||
let
|
||||
val chr = Char.toString chr ^ "\n"
|
||||
val () = print chr
|
||||
(* 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
|
||||
|
||||
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
||||
val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
(* todo: call to retrieve newCursorIdx should be below *)
|
||||
val newCursorIdx = cursorIdx + 1
|
||||
|
||||
(* move LineGap to first line displayed on screen, and build new text *)
|
||||
val newBuffer = LineGap.goToLine (startLine, newBuffer)
|
||||
val drawMsg = TextBuilder.build
|
||||
(startLine, cursorIdx, newBuffer, windowWidth, windowHeight)
|
||||
|
||||
val newApp = AppWith.bufferAndCursorIdx (app, newBuffer, newCursorIdx)
|
||||
in
|
||||
(app, [])
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
|
||||
fun handleChr (app: app_type, chr) =
|
||||
case chr of
|
||||
#"l" => moveRight app
|
||||
| _ => (app, [])
|
||||
|
||||
fun update (app, msg) =
|
||||
case msg of
|
||||
RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
||||
|
||||
@@ -14,4 +14,17 @@ struct
|
||||
, cursorIdx = cursorIdx
|
||||
}
|
||||
end
|
||||
|
||||
fun bufferAndCursorIdx (app: app_type, newBuffer, newCursorIdx) =
|
||||
let
|
||||
val {buffer = _, cursorIdx = _, windowWidth, windowHeight, startLine} =
|
||||
app
|
||||
in
|
||||
{ buffer = newBuffer
|
||||
, cursorIdx = newCursorIdx
|
||||
, windowWidth = windowWidth
|
||||
, windowHeight = windowHeight
|
||||
, startLine = startLine
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -286,17 +286,34 @@ struct
|
||||
if pos < String.size str then
|
||||
case String.sub (str, pos) of
|
||||
#" " =>
|
||||
buildTextStringWithinCursor
|
||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
||||
)
|
||||
(* if inside cursor, then create cursorAcc;
|
||||
* else, just skip as usual *)
|
||||
if absIdx <> cursorPos then
|
||||
(* not in cursur *)
|
||||
buildTextStringWithinCursor
|
||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
||||
)
|
||||
else
|
||||
(* in cursor *)
|
||||
let
|
||||
val cursorAcc = buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g ,b)
|
||||
in
|
||||
buildTextStringAfterCursor
|
||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||
, r, g, b, tl, cursorAcc
|
||||
)
|
||||
end
|
||||
| #"\t" =>
|
||||
(* todo: draw cursor if cursor is on tab
|
||||
* but this is not a priority right now *)
|
||||
buildTextStringWithinCursor
|
||||
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
||||
)
|
||||
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
||||
)
|
||||
| #"\n" =>
|
||||
if posY + ySpace < windowHeight then
|
||||
buildTextStringWithinCursor
|
||||
|
||||
Reference in New Issue
Block a user