From 1f7dbf31c6cb66bc176d9b97ad177bfa156ad9b1 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 10 Nov 2021 16:49:02 +0800 Subject: [PATCH 1/4] add wonly --- book/src/keymap.md | 1 + helix-term/src/commands.rs | 15 +++++++++++++++ helix-term/src/keymap.rs | 2 ++ 3 files changed, 18 insertions(+) diff --git a/book/src/keymap.md b/book/src/keymap.md index 212ed496531b..cb45005f800c 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -194,6 +194,7 @@ This layer is similar to vim keybindings as kakoune does not support window. | `k`, `Ctrl-k`, `up` | Move to split above | `jump_view_up` | | `l`, `Ctrl-l`, `right` | Move to right split | `jump_view_right` | | `q`, `Ctrl-q` | Close current window | `wclose` | +| `o`, `Ctrl-o` | Current window only | `wonly` | #### Space mode diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 489308d878df..089f92f1db72 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -320,6 +320,7 @@ impl Command { hsplit, "Horizontal bottom split", vsplit, "Vertical right split", wclose, "Close window", + wonly, "Current window only", select_register, "Select register", align_view_middle, "Align view middle", align_view_top, "Align view top", @@ -4723,6 +4724,20 @@ fn wclose(cx: &mut Context) { cx.editor.close(view_id, /* close_buffer */ false); } +fn wonly(cx: &mut Context) { + let views = cx + .editor + .tree + .views() + .map(|(v, focus)| (v.id, focus)) + .collect::>(); + for (view_id, focus) in views { + if !focus { + cx.editor.close(view_id, /* close_buffer */ false); + } + } +} + fn select_register(cx: &mut Context) { cx.on_next_key(move |cx, event| { if let Some(ch) = event.char() { diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 593ff0f0fa29..ecd54f28c079 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -545,11 +545,13 @@ impl Default for Keymaps { "C-u" => half_page_up, "C-d" => half_page_down, + // TODO extract the common binding with `Space w` "C-w" => { "Window" "C-w" | "w" => rotate_view, "C-s" | "s" => hsplit, "C-v" | "v" => vsplit, "C-q" | "q" => wclose, + "C-o" | "o" => wonly, "C-h" | "h" | "left" => jump_view_left, "C-j" | "j" | "down" => jump_view_down, "C-k" | "k" | "up" => jump_view_up, From f92642d85250b50f2ec0084f08eff272207231ee Mon Sep 17 00:00:00 2001 From: Bob Date: Thu, 11 Nov 2021 09:08:07 +0800 Subject: [PATCH 2/4] Update book/src/keymap.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Hrastnik --- book/src/keymap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index cb45005f800c..901c84711c72 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -194,7 +194,7 @@ This layer is similar to vim keybindings as kakoune does not support window. | `k`, `Ctrl-k`, `up` | Move to split above | `jump_view_up` | | `l`, `Ctrl-l`, `right` | Move to right split | `jump_view_right` | | `q`, `Ctrl-q` | Close current window | `wclose` | -| `o`, `Ctrl-o` | Current window only | `wonly` | +| `o`, `Ctrl-o` | Only keep the current window, closing all the others | `wonly` | #### Space mode From b50c467c58d8f9cce3d44b01b9ba0eb019c53d4c Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Thu, 11 Nov 2021 09:36:15 +0800 Subject: [PATCH 3/4] add `wonly` to space w mode too --- helix-term/src/keymap.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index ecd54f28c079..4820703b35ee 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -578,6 +578,7 @@ impl Default for Keymaps { "C-s" | "s" => hsplit, "C-v" | "v" => vsplit, "C-q" | "q" => wclose, + "C-o" | "o" => wonly, "C-h" | "h" | "left" => jump_view_left, "C-j" | "j" | "down" => jump_view_down, "C-k" | "k" | "up" => jump_view_up, From 012b262fe81953807aa10bfd21a151597ebc3dfb Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Thu, 11 Nov 2021 10:19:29 +0800 Subject: [PATCH 4/4] remove the TODO --- helix-term/src/keymap.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index ba9e1551a511..d7040b886449 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -578,7 +578,6 @@ impl Default for Keymaps { "C-u" => half_page_up, "C-d" => half_page_down, - // TODO extract the common binding with `Space w` "C-w" => { "Window" "C-w" | "w" => rotate_view, "C-s" | "s" => hsplit,