begin reimplementing motion to move cursor up (vi's 'k' command), although it is in progress and buggy
This commit is contained in:
@@ -148,7 +148,7 @@ struct
|
|||||||
case chr of
|
case chr of
|
||||||
#"h" => MoveViH.move (app, count)
|
#"h" => MoveViH.move (app, count)
|
||||||
| #"j" => MoveViJ.move (app, count)
|
| #"j" => MoveViJ.move (app, count)
|
||||||
| #"k" => MoveViK.move (app, count)
|
| #"k" => NormalMove.moveCursorUp (app, count)
|
||||||
| #"l" => MoveViL.move (app, count)
|
| #"l" => MoveViL.move (app, count)
|
||||||
| #"w" => MoveToNextWord.move (app, count)
|
| #"w" => MoveToNextWord.move (app, count)
|
||||||
| #"W" => MoveToNextWORD.move (app, count)
|
| #"W" => MoveToNextWORD.move (app, count)
|
||||||
|
|||||||
@@ -106,6 +106,83 @@ struct
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun moveCursorUp (app: app_type, count) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, cursorIdx
|
||||||
|
, buffer
|
||||||
|
, startLine = prevLineNumber
|
||||||
|
, searchList
|
||||||
|
, searchString
|
||||||
|
, bufferModifyTime
|
||||||
|
, visualScrollColumn = prevScrollColumn
|
||||||
|
, ...
|
||||||
|
} = app
|
||||||
|
|
||||||
|
(* calculate new idx to move to *)
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
||||||
|
val column = cursorIdx - startOfLine
|
||||||
|
|
||||||
|
val cursorLineNumber = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||||
|
val newCursorLineNumber = Int.max (cursorLineNumber - count, 0)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
|
||||||
|
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
|
||||||
|
val buffer = LineGap.goToIdx (lineIdx, buffer)
|
||||||
|
val lineIdx =
|
||||||
|
if Cursor.isNextChrEndOfLine (buffer, lineIdx) then cursorIdx
|
||||||
|
else lineIdx + 1
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (lineIdx, buffer)
|
||||||
|
val endOfLineIdx = Cursor.viDlr (buffer, lineIdx, 1)
|
||||||
|
|
||||||
|
val cursorIdx = Int.min (endOfLineIdx, lineIdx + column)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
|
||||||
|
(* create draw message *)
|
||||||
|
val visualScrollColumn =
|
||||||
|
TextScroll.getScrollColumn
|
||||||
|
(buffer, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
|
|
||||||
|
val startLine =
|
||||||
|
TextScroll.getStartLine
|
||||||
|
(prevLineNumber, newCursorLineNumber, windowHeight)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
|
val drawMsg = NormalModeTextBuilder.build
|
||||||
|
( startLine
|
||||||
|
, cursorIdx
|
||||||
|
, buffer
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, searchList
|
||||||
|
, searchString
|
||||||
|
, visualScrollColumn
|
||||||
|
)
|
||||||
|
val drawMsg = Vector.concat drawMsg
|
||||||
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
||||||
|
val drawMsg = [MailboxType.DRAW drawMsg]
|
||||||
|
|
||||||
|
val mode = NORMAL_MODE ""
|
||||||
|
in
|
||||||
|
NormalModeWith.bufferAndCursorIdx
|
||||||
|
( app
|
||||||
|
, buffer
|
||||||
|
, cursorIdx
|
||||||
|
, mode
|
||||||
|
, startLine
|
||||||
|
, searchList
|
||||||
|
, drawMsg
|
||||||
|
, bufferModifyTime
|
||||||
|
, visualScrollColumn
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
fun moveToLine (app: app_type, reqLine) =
|
fun moveToLine (app: app_type, reqLine) =
|
||||||
let
|
let
|
||||||
val reqLine = reqLine - 1
|
val reqLine = reqLine - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user