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)
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun handleChr (app, chr) =
|
fun moveRight (app: app_type) =
|
||||||
let
|
let
|
||||||
val chr = Char.toString chr ^ "\n"
|
(* todo: proper implementation of moveRight
|
||||||
val () = print chr
|
* 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
|
in
|
||||||
(app, [])
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun handleChr (app: app_type, chr) =
|
||||||
|
case chr of
|
||||||
|
#"l" => moveRight app
|
||||||
|
| _ => (app, [])
|
||||||
|
|
||||||
fun update (app, msg) =
|
fun update (app, msg) =
|
||||||
case msg of
|
case msg of
|
||||||
RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
||||||
|
|||||||
@@ -14,4 +14,17 @@ struct
|
|||||||
, cursorIdx = cursorIdx
|
, cursorIdx = cursorIdx
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -286,17 +286,34 @@ struct
|
|||||||
if pos < String.size str then
|
if pos < String.size str then
|
||||||
case String.sub (str, pos) of
|
case String.sub (str, pos) of
|
||||||
#" " =>
|
#" " =>
|
||||||
buildTextStringWithinCursor
|
(* if inside cursor, then create cursorAcc;
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
* else, just skip as usual *)
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
if absIdx <> cursorPos then
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
(* 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" =>
|
| #"\t" =>
|
||||||
|
(* todo: draw cursor if cursor is on tab
|
||||||
|
* but this is not a priority right now *)
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
|
||||||
)
|
)
|
||||||
| #"\n" =>
|
| #"\n" =>
|
||||||
if posY + ySpace < windowHeight then
|
if posY + ySpace < windowHeight then
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
|
|||||||
Reference in New Issue
Block a user