aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs53
-rw-r--r--helix-term/src/keymap.rs5
2 files changed, 40 insertions, 18 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index bff102dc..c88a5eee 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2240,11 +2240,6 @@ pub fn hover(cx: &mut Context) {
);
}
-// view movements
-pub fn next_view(cx: &mut Context) {
- cx.editor.focus_next()
-}
-
// comments
pub fn toggle_comments(cx: &mut Context) {
let (view, doc) = cx.current();
@@ -2308,16 +2303,38 @@ pub fn jump_backward(cx: &mut Context) {
};
}
-//
+pub fn window_mode(cx: &mut Context) {
+ cx.on_next_key(move |cx, event| {
+ if let KeyEvent {
+ code: KeyCode::Char(ch),
+ ..
+ } = event
+ {
+ match ch {
+ 'w' => rotate_view(cx),
+ 'h' => hsplit(cx),
+ 'v' => vsplit(cx),
+ 'q' => wclose(cx),
+ _ => {}
+ }
+ }
+ })
+}
-pub fn vsplit(cx: &mut Context) {
+pub fn rotate_view(cx: &mut Context) {
+ cx.editor.focus_next()
+}
+
+// split helper, clear it later
+use helix_view::editor::Action;
+fn split(cx: &mut Context, action: Action) {
use helix_view::editor::Action;
let (view, doc) = cx.current();
let id = doc.id();
let selection = doc.selection(view.id).clone();
let first_line = view.first_line;
- cx.editor.switch(id, Action::VerticalSplit);
+ cx.editor.switch(id, action);
// match the selection in the previous view
let (view, doc) = cx.current();
@@ -2325,6 +2342,20 @@ pub fn vsplit(cx: &mut Context) {
doc.set_selection(view.id, selection);
}
+pub fn hsplit(cx: &mut Context) {
+ split(cx, Action::HorizontalSplit);
+}
+
+pub fn vsplit(cx: &mut Context) {
+ split(cx, Action::VerticalSplit);
+}
+
+pub fn wclose(cx: &mut Context) {
+ let view_id = cx.view().id;
+ // close current split
+ cx.editor.close(view_id, /* close_buffer */ false);
+}
+
pub fn space_mode(cx: &mut Context) {
cx.on_next_key(move |cx, event| {
if let KeyEvent {
@@ -2336,18 +2367,12 @@ pub fn space_mode(cx: &mut Context) {
match ch {
'f' => file_picker(cx),
'b' => buffer_picker(cx),
- 'v' => vsplit(cx),
'w' => {
// save current buffer
let (view, doc) = cx.current();
doc.format(view.id); // TODO: merge into save
tokio::spawn(doc.save());
}
- 'c' => {
- let view_id = cx.view().id;
- // close current split
- cx.editor.close(view_id, /* close_buffer */ false);
- }
// ' ' => toggle_alternate_buffer(cx),
// TODO: temporary since space mode took it's old key
' ' => keep_primary_selection(cx),
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 7376cd03..e51dfbc5 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -264,10 +264,7 @@ pub fn default() -> Keymaps {
ctrl!('u') => commands::half_page_up,
ctrl!('d') => commands::half_page_down,
- KeyEvent {
- code: KeyCode::Tab,
- modifiers: KeyModifiers::NONE
- } => commands::next_view,
+ ctrl!('w') => commands::window_mode,
// move under <space>c
ctrl!('c') => commands::toggle_comments,