diff --git a/src/Feature/Vim/Feature_Vim.re b/src/Feature/Vim/Feature_Vim.re index 54f760112a..02c2ac2e59 100644 --- a/src/Feature/Vim/Feature_Vim.re +++ b/src/Feature/Vim/Feature_Vim.re @@ -162,13 +162,68 @@ module Effects = { ); }); }; + + let command = cmd => { + Isolinear.Effect.createWithDispatch( + ~name="Feature_Vim.Effect.command", dispatch => { + let context = Vim.Context.current(); + let (newContext, effects) = Vim.command(~context, cmd); + + dispatch( + ModeChanged({ + allowAnimation: false, + mode: newContext.mode, + subMode: newContext.subMode, + effects, + }), + ); + }); + }; }; -let update = (msg, model: model) => { +let update = (~cursor, ~selections, msg, model: model) => { switch (msg) { | Command(command) => - prerr_endline("COMMAND: " ++ show_command(command)); - failwith("Done"); + let (startLine, stopLine) = + switch (selections) { + | [visualRange, ..._] => + let range = Oni_Core.VisualRange.(visualRange.range); + ByteRange.(range.start.line, range.stop.line); + | [] => BytePosition.(cursor.line, cursor.line) + }; + let cmd = + switch (command) { + | MoveSelectionDownward + | MoveSelectionUpward => "m" + + | CopySelectionDownward + | CopySelectionUpward => "t" + }; + + let destination = + EditorCoreTypes.( + switch (command) { + | MoveSelectionDownward => LineNumber.(stopLine + 1) + | MoveSelectionUpward => LineNumber.(startLine - 2) + | CopySelectionUpward => LineNumber.(startLine - 1) + | CopySelectionDownward => stopLine + } + ); + + let eff = + EditorCoreTypes.( + Effects.command( + Printf.sprintf( + "%s,%s%s%d", + startLine |> LineNumber.toOneBased |> string_of_int, + stopLine |> LineNumber.toOneBased |> string_of_int, + cmd, + destination |> LineNumber.toOneBased, + ), + ) + ); + + (model, Effect(eff)); | ModeChanged({allowAnimation, mode, effects, subMode}) => ( {...model, subMode} |> handleEffects(effects), @@ -278,14 +333,6 @@ let sub = (~buffer, ~topVisibleLine, ~bottomVisibleLine, model) => { module Commands = { open Feature_Commands.Schema; - let moveLinesDown = - define( - ~category="Editor", - ~title="Move lines down", - "editor.action.moveLinesDownAction", - Command(MoveSelectionDownward), - ); - let moveLinesDown = define( ~title="Move Line Down", diff --git a/src/Feature/Vim/Feature_Vim.rei b/src/Feature/Vim/Feature_Vim.rei index 9ca43fdc23..fce3fa77f8 100644 --- a/src/Feature/Vim/Feature_Vim.rei +++ b/src/Feature/Vim/Feature_Vim.rei @@ -57,7 +57,14 @@ type outmsg = // UPDATE -let update: (msg, model) => (model, outmsg); +let update: + ( + ~cursor: BytePosition.t, + ~selections: list(Oni_Core.VisualRange.t), + msg, + model + ) => + (model, outmsg); let getSearchHighlightsByLine: (~bufferId: int, ~line: LineNumber.t, model) => list(ByteRange.t); diff --git a/src/Store/Features.re b/src/Store/Features.re index 6ac3af3283..6bda1e35c6 100644 --- a/src/Store/Features.re +++ b/src/Store/Features.re @@ -2243,7 +2243,12 @@ let update = | Vim(msg) => let previousSubMode = state.vim |> Feature_Vim.subMode; - let (vim, outmsg) = Feature_Vim.update(msg, state.vim); + let editor = state.layout |> Feature_Layout.activeEditor; + let cursor = editor |> Feature_Editor.Editor.getPrimaryCursorByte; + + let selections = editor |> Feature_Editor.Editor.selections; + let (vim, outmsg) = + Feature_Vim.update(~cursor, ~selections, msg, state.vim); let newSubMode = state.vim |> Feature_Vim.subMode; // If we've switched to, or from, insert literal, diff --git a/src/editor-core-types/BytePosition.re b/src/editor-core-types/BytePosition.re index 80d51ee1ea..782e58ece0 100644 --- a/src/editor-core-types/BytePosition.re +++ b/src/editor-core-types/BytePosition.re @@ -21,3 +21,8 @@ let compare = (a, b) => } else { LineNumber.toZeroBased(a.line) - LineNumber.toZeroBased(b.line); }; + +let shiftLine = (~delta, bytePos) => { + ...bytePos, + line: LineNumber.(bytePos.line + delta), +}; diff --git a/src/editor-core-types/BytePosition.rei b/src/editor-core-types/BytePosition.rei index bd087e2c5b..0a8815c792 100644 --- a/src/editor-core-types/BytePosition.rei +++ b/src/editor-core-types/BytePosition.rei @@ -19,3 +19,5 @@ let (==): (t, t) => bool; * - a positive integer if a is greater than b */ let compare: (t, t) => int; + +let shiftLine: (~delta: int, t) => t;