Skip to content

Commit

Permalink
feat(layout/#592): layout tabs - part 2 - :tab* commands and gt/gT (
Browse files Browse the repository at this point in the history
#2030)

* wire up gt and gT

* wire up libvim tab page callback

* wire up :tabclose

* add argument to tabclose

* wire up tabonly

* tabmove

* switch to new protocol with relative support

* implement MoveRelative

* CloseRelative

* OnlyRelative

* typo

* dependency: libvim -> 8.10869.51
  • Loading branch information
glennsl authored Jun 28, 2020
1 parent 2470fbe commit b9961f0
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 26 deletions.
12 changes: 6 additions & 6 deletions bench.esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions integrationtest.esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
"esy-sdl2": "*",
"esy-skia": "*",
"isolinear": "^3.0.0",
"libvim": "8.10869.50",
"libvim": "8.10869.51",
"ocaml": "~4.7.0",
"reason-native-crash-utils": "onivim/reason-native-crash-utils#38c8f00",
"reason-tree-sitter": "^1.0.1001",
Expand Down
72 changes: 72 additions & 0 deletions src/Core/Utility/ListEx.re
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,75 @@ let findIndex = (predicate, list) => {
| [_, ...tail] => loop(i + 1, tail);
loop(0, list);
};

/**
* removeAt
*/
let removeAt = (index, list) => {
let left = Base.List.take(list, index);
let right = Base.List.drop(list, index + 1);
left @ right;
};

let%test_module "removeAt" =
(module
{
let%test "0" = removeAt(0, [1, 2, 3]) == [2, 3];
let%test "1" = removeAt(1, [1, 2, 3]) == [1, 3];
let%test "2" = removeAt(2, [1, 2, 3]) == [1, 2];
let%test "-10 (out of bounds)" = removeAt(-10, [1, 2, 3]) == [1, 2, 3];
let%test "10 (out of bounds)" = removeAt(10, [1, 2, 3]) == [1, 2, 3];
});

/**
* insertAt
*/
let insertAt = (index, element, list) => {
let (left, right) = Base.List.split_n(list, index);
left @ [element] @ right;
};

let%test_module "insertAt" =
(module
{
let%test "0" = insertAt(0, 42, [1, 2, 3]) == [42, 1, 2, 3];
let%test "1" = insertAt(1, 42, [1, 2, 3]) == [1, 42, 2, 3];
let%test "2" = insertAt(2, 42, [1, 2, 3]) == [1, 2, 42, 3];
let%test "3" = insertAt(3, 42, [1, 2, 3]) == [1, 2, 3, 42];
let%test "-10 (out of bounds)" =
insertAt(-10, 42, [1, 2, 3]) == [42, 1, 2, 3];
let%test "10 (out of bounds)" =
insertAt(10, 42, [1, 2, 3]) == [1, 2, 3, 42];
});

/**
* move
*/
let move = (~fromi, ~toi, list) => {
let element = List.nth(list, fromi);
list |> removeAt(fromi) |> insertAt(toi, element);
};

let%test_module "move" =
(module
{
let%test "0 -> 0" = move(~fromi=0, ~toi=0, [1, 2, 3]) == [1, 2, 3];
let%test "0 -> 1" = move(~fromi=0, ~toi=1, [1, 2, 3]) == [2, 1, 3];
let%test "0 -> 2" = move(~fromi=0, ~toi=2, [1, 2, 3]) == [2, 3, 1];
let%test "1 -> 0" = move(~fromi=1, ~toi=0, [1, 2, 3]) == [2, 1, 3];
let%test "1 -> 1" = move(~fromi=1, ~toi=1, [1, 2, 3]) == [1, 2, 3];
let%test "1 -> 2" = move(~fromi=1, ~toi=2, [1, 2, 3]) == [1, 3, 2];
let%test "2 -> 0" = move(~fromi=2, ~toi=0, [1, 2, 3]) == [3, 1, 2];
let%test "2 -> 1" = move(~fromi=2, ~toi=1, [1, 2, 3]) == [1, 3, 2];
let%test "2 -> 2" = move(~fromi=2, ~toi=2, [1, 2, 3]) == [1, 2, 3];
let%test "-10 -> 1 (out of bounds)" =
switch (move(~fromi=-10, ~toi=1, [1, 2, 3])) {
| exception (Invalid_argument(_)) => true
| _ => false
};
let%test "10 -> 1 (out of bounds)" =
switch (move(~fromi=10, ~toi=1, [1, 2, 3])) {
| exception (Failure(_)) => true
| _ => false
};
});
10 changes: 10 additions & 0 deletions src/Feature/Layout/Feature_Layout.rei
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ let openEditor: (~config: Config.resolver, Editor.t, model) => model;
let closeBuffer: (~force: bool, Vim.Types.buffer, model) => option(model);

let addLayoutTab: model => model;
let gotoLayoutTab: (int, model) => model;
let previousLayoutTab: (~count: int=?, model) => model;
let nextLayoutTab: (~count: int=?, model) => model;
let removeLayoutTab: (int, model) => option(model);
let removeLayoutTabRelative: (~delta: int, model) => option(model);
let removeActiveLayoutTab: model => option(model);
let removeOtherLayoutTabs: model => model;
let removeOtherLayoutTabsRelative: (~count: int, model) => model;
let moveActiveLayoutTabTo: (int, model) => model;
let moveActiveLayoutTabRelative: (int, model) => model;

let map: (Editor.t => Editor.t, model) => model;

Expand Down
48 changes: 48 additions & 0 deletions src/Feature/Layout/Model.re
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ let removeLayoutTab = (index, model) => {
};
};

let removeLayoutTabRelative = (~delta, model) =>
removeLayoutTab(model.activeLayoutIndex + delta, model);

let removeActiveLayoutTab = model =>
removeLayoutTab(model.activeLayoutIndex, model);

let removeOtherLayoutTabs = model => {
layouts: [activeLayout(model)],
activeLayoutIndex: 0,
};

let removeOtherLayoutTabsRelative = (~count, model) => {
let (start, stop) =
count < 0
? (model.activeLayoutIndex + count, model.activeLayoutIndex - 1)
: (model.activeLayoutIndex + 1, model.activeLayoutIndex + count);
{
layouts: ListEx.sublist(start, stop, model.layouts),
activeLayoutIndex: 0,
};
};

let removeEditor = (editorId, model) => {
let removeFromLayout = layout => {
let groups =
Expand Down Expand Up @@ -367,6 +389,32 @@ let addLayoutTab = model => {
};
};

let gotoLayoutTab = (index, model) => {
...model,
activeLayoutIndex:
IntEx.clamp(index, ~lo=0, ~hi=List.length(model.layouts) - 1),
};

let previousLayoutTab = (~count=1, model) =>
gotoLayoutTab(model.activeLayoutIndex - count, model);

let nextLayoutTab = (~count=1, model) =>
gotoLayoutTab(model.activeLayoutIndex + count, model);

let moveActiveLayoutTabTo = (index, model) => {
let newLayouts =
ListEx.move(~fromi=model.activeLayoutIndex, ~toi=index, model.layouts);

{
layouts: newLayouts,
activeLayoutIndex:
IntEx.clamp(index, ~lo=0, ~hi=List.length(newLayouts) - 1),
};
};

let moveActiveLayoutTabRelative = (delta, model) =>
moveActiveLayoutTabTo(model.activeLayoutIndex + delta, model);

let map = (f, model) => {
...model,
layouts:
Expand Down
1 change: 1 addition & 0 deletions src/Model/Actions.re
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ type t =
decorations: list(Decoration.t),
})
| Vim(Feature_Vim.msg)
| TabPage(Vim.TabPage.effect)
| Noop
and command = {
commandCategory: option(string),
Expand Down
Loading

0 comments on commit b9961f0

Please sign in to comment.