Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wonly -- window only #1057

Merged
merged 5 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | Only keep the current window, closing all the others | `wonly` |

#### Space mode

Expand Down
15 changes: 15 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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::<Vec<_>>();
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() {
Expand Down
3 changes: 3 additions & 0 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,13 @@ impl Default for Keymaps {
"C-u" => half_page_up,
"C-d" => half_page_down,

// TODO extract the common binding with `Space w`
QiBaobin marked this conversation as resolved.
Show resolved Hide resolved
"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,
Expand All @@ -609,6 +611,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,
Expand Down