Skip to content

Commit 8244383

Browse files
committed
Add bindings for copy downward / upward
1 parent 2eee58b commit 8244383

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

src/Feature/Vim/Feature_Vim.re

+129-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ let moveMarkers = (~newBuffer, ~markerUpdate, model) => {
5959

6060
// MSG
6161

62+
[@deriving show]
63+
type command =
64+
| MoveSelectionUpward
65+
| MoveSelectionDownward
66+
| CopySelectionUpward
67+
| CopySelectionDownward;
68+
6269
[@deriving show]
6370
type msg =
71+
| Command(command)
6472
| ModeChanged({
6573
allowAnimation: bool,
6674
mode: [@opaque] Vim.Mode.t,
@@ -158,6 +166,10 @@ module Effects = {
158166

159167
let update = (msg, model: model) => {
160168
switch (msg) {
169+
| Command(command) =>
170+
prerr_endline("COMMAND: " ++ show_command(command));
171+
failwith("Done");
172+
161173
| ModeChanged({allowAnimation, mode, effects, subMode}) => (
162174
{...model, subMode} |> handleEffects(effects),
163175
ModeDidChange({allowAnimation, mode, effects}),
@@ -263,6 +275,46 @@ let sub = (~buffer, ~topVisibleLine, ~bottomVisibleLine, model) => {
263275
|> Option.value(~default=Isolinear.Sub.none);
264276
};
265277

278+
module Commands = {
279+
open Feature_Commands.Schema;
280+
281+
let moveLinesDown =
282+
define(
283+
~category="Editor",
284+
~title="Move lines down",
285+
"editor.action.moveLinesDownAction",
286+
Command(MoveSelectionDownward),
287+
);
288+
289+
let moveLinesDown =
290+
define(
291+
~title="Move Line Down",
292+
"editor.action.moveLinesDownAction",
293+
Command(MoveSelectionDownward),
294+
);
295+
296+
let moveLinesUp =
297+
define(
298+
~title="Move Line Up",
299+
"editor.action.moveLinesUpAction",
300+
Command(MoveSelectionUpward),
301+
);
302+
303+
let copyLinesDown =
304+
define(
305+
~category="Copy Line Down",
306+
"editor.action.copyLinesDownAction",
307+
Command(CopySelectionDownward),
308+
);
309+
310+
let copyLinesUp =
311+
define(
312+
~category="Copy Line Up",
313+
"editor.action.copyLinesUpAction",
314+
Command(CopySelectionUpward),
315+
);
316+
};
317+
266318
module Keybindings = {
267319
open Feature_Input.Schema;
268320
let controlSquareBracketRemap =
@@ -272,10 +324,86 @@ module Keybindings = {
272324
~toKeys="<ESC>",
273325
~condition=WhenExpr.Value(True),
274326
);
327+
328+
let editCondition =
329+
WhenExpr.parse(
330+
"normalMode || visualMode || insertMode && editorTextFocus",
331+
);
332+
333+
let moveLineDownwardJ =
334+
bind(
335+
~key="<A-j>",
336+
~command=Commands.moveLinesDown.id,
337+
~condition=editCondition,
338+
);
339+
340+
let moveLineDownwardArrow =
341+
bind(
342+
~key="<A-Down>",
343+
~command=Commands.moveLinesDown.id,
344+
~condition=editCondition,
345+
);
346+
347+
let moveLineUpwardK =
348+
bind(
349+
~key="<A-k>",
350+
~command=Commands.moveLinesUp.id,
351+
~condition=editCondition,
352+
);
353+
354+
let moveLineUpwardArrow =
355+
bind(
356+
~key="<A-Up>",
357+
~command=Commands.moveLinesUp.id,
358+
~condition=editCondition,
359+
);
360+
361+
let copyLineDownwardJ =
362+
bind(
363+
~key="<A-S-j>",
364+
~command=Commands.copyLinesDown.id,
365+
~condition=editCondition,
366+
);
367+
368+
let copyLineDownwardArrow =
369+
bind(
370+
~key="<A-S-Down>",
371+
~command=Commands.copyLinesDown.id,
372+
~condition=editCondition,
373+
);
374+
375+
let copyLineUpwardK =
376+
bind(
377+
~key="<A-S-k>",
378+
~command=Commands.copyLinesUp.id,
379+
~condition=editCondition,
380+
);
381+
382+
let copyLineUpwardArrow =
383+
bind(
384+
~key="<A-S-Up>",
385+
~command=Commands.copyLinesUp.id,
386+
~condition=editCondition,
387+
);
275388
};
276389

277390
module Contributions = {
278-
let keybindings = Keybindings.[controlSquareBracketRemap];
391+
let commands =
392+
Commands.[moveLinesDown, moveLinesUp, copyLinesDown, copyLinesUp];
393+
let keybindings =
394+
Keybindings.[
395+
// Remaps
396+
controlSquareBracketRemap,
397+
// Bindings
398+
moveLineDownwardJ,
399+
moveLineDownwardArrow,
400+
moveLineUpwardK,
401+
moveLineUpwardArrow,
402+
copyLineDownwardJ,
403+
copyLineDownwardArrow,
404+
copyLineUpwardArrow,
405+
copyLineUpwardK,
406+
];
279407

280408
let configuration = Configuration.[experimentalViml.spec];
281409
};

src/Feature/Vim/Feature_Vim.rei

+5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ let experimentalViml: model => list(string);
1414

1515
// MSG
1616

17+
[@deriving show]
18+
type command;
19+
1720
[@deriving show]
1821
type msg =
22+
| Command(command)
1923
| ModeChanged({
2024
allowAnimation: bool,
2125
mode: [@opaque] Vim.Mode.t,
@@ -103,6 +107,7 @@ module Configuration: {
103107
};
104108

105109
module Contributions: {
110+
let commands: list(Oni_Core.Command.t(msg));
106111
let keybindings: list(Feature_Input.Schema.keybinding);
107112
let configuration: list(Oni_Core.Config.Schema.spec);
108113
};

src/Model/CommandManager.re

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ let current = {
2424
Feature_Help.Contributions.commands
2525
|> Command.Lookup.fromList
2626
|> Command.Lookup.map(msg => Actions.Help(msg)),
27+
Feature_Vim.Contributions.commands
28+
|> Command.Lookup.fromList
29+
|> Command.Lookup.map(msg => Actions.Vim(msg)),
2730
Feature_Zen.Contributions.commands
2831
|> Command.Lookup.fromList
2932
|> Command.Lookup.map(msg => Actions.Zen(msg)),

0 commit comments

Comments
 (0)