Skip to content

Commit

Permalink
Initial implementation for #3325
Browse files Browse the repository at this point in the history
  • Loading branch information
bryphe committed Mar 31, 2021
1 parent 8244383 commit 8474b87
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
69 changes: 58 additions & 11 deletions src/Feature/Vim/Feature_Vim.re
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/Feature/Vim/Feature_Vim.rei
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/Store/Features.re
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/editor-core-types/BytePosition.re
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
2 changes: 2 additions & 0 deletions src/editor-core-types/BytePosition.rei
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8474b87

Please sign in to comment.