diff --git a/fcore/app-update.sml b/fcore/app-update.sml index ab0f193..521cc2e 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -262,34 +262,34 @@ struct let (* delete char at cursor and then decrement cursorIdx by 1 * if cursorIdx is not 0 *) - val newBuffer = LineGap.delete (cursorIdx, 1, buffer) + val buffer = LineGap.delete (cursorIdx, 1, buffer) val cursorIdx = - if Cursor.isPrevChrStartOfLine (newBuffer, cursorIdx) + if Cursor.isPrevChrStartOfLine (buffer, cursorIdx) orelse cursorIdx = 0 then cursorIdx else cursorIdx - 1 - val newBuffer = LineGap.goToLine (startLine, newBuffer) + val buffer = LineGap.goToLine (startLine, buffer) val newApp = AppWith.bufferAndCursorIdx - (app, newBuffer, cursorIdx, NORMAL_MODE "", startLine) + (app, buffer, cursorIdx, NORMAL_MODE "", startLine) val drawMsg = TextBuilder.build - (startLine, cursorIdx, newBuffer, windowWidth, windowHeight) + (startLine, cursorIdx, buffer, windowWidth, windowHeight) in (newApp, drawMsg) end else let - val newBuffer = LineGap.delete (cursorIdx, 1, buffer) + val buffer = LineGap.delete (cursorIdx, 1, buffer) - val newBuffer = LineGap.goToLine (startLine, newBuffer) + val buffer = LineGap.goToLine (startLine, buffer) val newApp = AppWith.bufferAndCursorIdx - (app, newBuffer, cursorIdx, NORMAL_MODE "", startLine) + (app, buffer, cursorIdx, NORMAL_MODE "", startLine) val drawMsg = TextBuilder.build - (startLine, cursorIdx, newBuffer, windowWidth, windowHeight) + (startLine, cursorIdx, buffer, windowWidth, windowHeight) in (newApp, drawMsg) end diff --git a/fcore/text-window.sml b/fcore/text-window.sml index 1c13906..01be38d 100644 --- a/fcore/text-window.sml +++ b/fcore/text-window.sml @@ -20,23 +20,24 @@ struct | [] => 0 else - let - val chr = String.sub (shd, sIdx) - in - if chr = #"\n" then - if absIdx <> cursorIdx then - getStartLineBefore - (sIdx - 1, shd, lineNum - 1, absIdx - 1, cursorIdx, stl) + if absIdx <= cursorIdx then + lineNum + else + let + val chr = String.sub (shd, sIdx) + in + if chr = #"\n" then + if isPrevChrLn (shd, sIdx, stl) then + (* \n -> \n *) + getStartLineBefore + (sIdx - 1, shd, lineNum - 1, absIdx - 1, cursorIdx, stl) + else + (* graphical-chr -> \n *) + getStartLineBefore + (sIdx - 1, shd, lineNum, absIdx - 1, cursorIdx, stl) else - (* we have found cursor, and it is at \n *) - lineNum - 1 - else - if absIdx <> cursorIdx then getStartLineBefore (sIdx - 1, shd, lineNum, absIdx - 1, cursorIdx, stl) - else - (* we have found cursor; return line *) - lineNum - 1 end fun getStartLineAfter diff --git a/shf b/shf index 3ef9f6f..5dfb3a8 100755 Binary files a/shf and b/shf differ