diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 6bf8132..3e772f0 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -461,11 +461,8 @@ struct fun parseYankTerminal (str, count, app, chrCmd, time) = case chrCmd of - (* motions like yh / yj / yk / yl are not really needed. - * Vim supports them, but I never use them. - * I also don't need yx (yank a character and then remove it) - * because I never do that. *) - #"y" => NormalYank.yankLine (app, count) + #"h" => NormalYank.yankLeft (app, count) + | #"y" => NormalYank.yankLine (app, count) | #"0" => NormalYank.yankToStartOfLine app | #"w" => NormalYank.yankWhenMovingForward (app, Cursor.nextWord, count) | #"W" => NormalYank.yankWhenMovingForward (app, Cursor.nextWORD, count) diff --git a/fcore/normal-mode/normal-yank.sml b/fcore/normal-mode/normal-yank.sml index c02978a..60851f7 100644 --- a/fcore/normal-mode/normal-yank.sml +++ b/fcore/normal-mode/normal-yank.sml @@ -4,6 +4,24 @@ struct open DrawMsg open MailboxType + fun yankLeft (app: app_type, count) = + let + val {buffer, cursorIdx, ...} = app + + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val min = Cursor.vi0 (buffer, cursorIdx) + val low = Cursor.viH (buffer, cursorIdx, 1) + + val low = Int.max (min, low) + val length = cursorIdx - low + val str = LineGap.substring (low, length, buffer) + + val msg = YANK str + val mode = NORMAL_MODE "" + in + NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) + end + fun yankLine (app: app_type, count) = let val {buffer, cursorIdx, ...} = app diff --git a/todo.md b/todo.md index f3e7568..dcb8b20 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,4 @@ # To-do list -- Add yank commands like yh/yj/yk/yl as well and then add tests for yanking. +- Implement `yh` motion. + - Implemented. Add tests for it next (based on tests for 'dh' motion).