diff --git a/fcore/app-update.sml b/fcore/app-update.sml index 38d262e..9be7621 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -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) diff --git a/fcore/app-with.sml b/fcore/app-with.sml index 513124c..25c6c51 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -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 diff --git a/fcore/text-builder.sml b/fcore/text-builder.sml index 6e0473f..11b6e7e 100644 --- a/fcore/text-builder.sml +++ b/fcore/text-builder.sml @@ -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 diff --git a/shf b/shf index dbab214..a8709fa 100755 Binary files a/shf and b/shf differ