on master help sign in
Add window mode

Fix #93

commit8c2fa12ffc006de787992b4022263be033ac8200 authorIvan Tham <pickfire@riseup.net> dateSat 5 Jun 2021, 15:45 (5 years ago) parent212f6bc
3 files changed+52−21
book/src/keymap.md+12−3 helix-term/src/commands.rs+39−14 helix-term/src/keymap.rs+1−4
book/src/keymap.md+12−3
@@ -24,13 +24,13 @@
2424| PageDown | Move page down |
2525| ctrl-u | Move half page up |
2626| ctrl-d | Move half page down |
27−| Tab | Switch to next view |
2827| ctrl-i | Jump forward on the jumplist TODO: conflicts tab |
2928| ctrl-o | Jump backward on the jumplist |
3029| v | Enter select (extend) mode |
3130| g | Enter goto mode |
3231| : | Enter command mode |
3332| z | Enter view mode |
33+| ctrl-w | Enter window mode |
3434| space | Enter space mode |
3535| K | Show documentation for the item under the cursor |
3636
@@ -132,6 +132,17 @@ Jumps to various locations.
132132
133133TODO: Mappings for selecting syntax nodes (a superset of `[`).
134134
135+## Window mode
136+
137+This layer is similar to vim keybindings as kakoune does not support window.
138+
139+| Key | Description |
140+|-----|-------------|
141+| w, ctrl-w | Switch to next window |
142+| v, ctrl-v | Vertical right split |
143+| h, ctrl-h | Horizontal bottom split |
144+| q, ctrl-q | Close current window |
145+
135146## Space mode
136147
137148This layer is a kludge of mappings I had under leader key in neovim.
@@ -140,7 +151,5 @@ This layer is a kludge of mappings I had under leader key in neovim.
140151|-----|-----------|
141152| f | Open file picker |
142153| b | Open buffer picker |
143−| v | Open a new vertical split into the current file |
144154| w | Save changes to file |
145−| c | Close the current split |
146155| space | Keep primary selection TODO: it's here because space mode replaced it |
helix-term/src/commands.rs+39−14
@@ -2240,11 +2240,6 @@ pub fn hover(cx: &mut Context) {
22402240 );
22412241}
22422242
2243−// view movements
2244−pub fn next_view(cx: &mut Context) {
2245− cx.editor.focus_next()
2246−}
2247−
22482243// comments
22492244pub fn toggle_comments(cx: &mut Context) {
22502245 let (view, doc) = cx.current();
@@ -2308,16 +2303,38 @@ pub fn jump_backward(cx: &mut Context) {
23082303 };
23092304}
23102305
2311−//
2306+pub fn window_mode(cx: &mut Context) {
2307+ cx.on_next_key(move |cx, event| {
2308+ if let KeyEvent {
2309+ code: KeyCode::Char(ch),
2310+ ..
2311+ } = event
2312+ {
2313+ match ch {
2314+ 'w' => rotate_view(cx),
2315+ 'h' => hsplit(cx),
2316+ 'v' => vsplit(cx),
2317+ 'q' => wclose(cx),
2318+ _ => {}
2319+ }
2320+ }
2321+ })
2322+}
23122323
2313−pub fn vsplit(cx: &mut Context) {
2324+pub fn rotate_view(cx: &mut Context) {
2325+ cx.editor.focus_next()
2326+}
2327+
2328+// split helper, clear it later
2329+use helix_view::editor::Action;
2330+fn split(cx: &mut Context, action: Action) {
23142331 use helix_view::editor::Action;
23152332 let (view, doc) = cx.current();
23162333 let id = doc.id();
23172334 let selection = doc.selection(view.id).clone();
23182335 let first_line = view.first_line;
23192336
2320− cx.editor.switch(id, Action::VerticalSplit);
2337+ cx.editor.switch(id, action);
23212338
23222339 // match the selection in the previous view
23232340 let (view, doc) = cx.current();
@@ -2325,6 +2342,20 @@ pub fn vsplit(cx: &mut Context) {
23252342 doc.set_selection(view.id, selection);
23262343}
23272344
2345+pub fn hsplit(cx: &mut Context) {
2346+ split(cx, Action::HorizontalSplit);
2347+}
2348+
2349+pub fn vsplit(cx: &mut Context) {
2350+ split(cx, Action::VerticalSplit);
2351+}
2352+
2353+pub fn wclose(cx: &mut Context) {
2354+ let view_id = cx.view().id;
2355+ // close current split
2356+ cx.editor.close(view_id, /* close_buffer */ false);
2357+}
2358+
23282359pub fn space_mode(cx: &mut Context) {
23292360 cx.on_next_key(move |cx, event| {
23302361 if let KeyEvent {
@@ -2336,18 +2367,12 @@ pub fn space_mode(cx: &mut Context) {
23362367 match ch {
23372368 'f' => file_picker(cx),
23382369 'b' => buffer_picker(cx),
2339− 'v' => vsplit(cx),
23402370 'w' => {
23412371 // save current buffer
23422372 let (view, doc) = cx.current();
23432373 doc.format(view.id); // TODO: merge into save
23442374 tokio::spawn(doc.save());
23452375 }
2346− 'c' => {
2347− let view_id = cx.view().id;
2348− // close current split
2349− cx.editor.close(view_id, /* close_buffer */ false);
2350− }
23512376 // ' ' => toggle_alternate_buffer(cx),
23522377 // TODO: temporary since space mode took it's old key
23532378 ' ' => keep_primary_selection(cx),
helix-term/src/keymap.rs+1−4
@@ -264,10 +264,7 @@ pub fn default() -> Keymaps {
264264 ctrl!('u') => commands::half_page_up,
265265 ctrl!('d') => commands::half_page_down,
266266
267− KeyEvent {
268− code: KeyCode::Tab,
269− modifiers: KeyModifiers::NONE
270− } => commands::next_view,
267+ ctrl!('w') => commands::window_mode,
271268
272269 // move under <space>c
273270 ctrl!('c') => commands::toggle_comments,