From 978c1a126d77aba03120bcca2a98e31639120416 Mon Sep 17 00:00:00 2001 From: sander777 Date: Mon, 23 Oct 2023 18:56:00 +0300 Subject: [PATCH] renaming;some key-mapping fixes;refactoring --- helix-term/src/commands.rs | 8 ++++---- helix-term/src/keymap/default.rs | 12 ++++++------ helix-view/src/editor.rs | 4 ++-- helix-view/src/tree.rs | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 592ef5260..2bb2076da 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -37,7 +37,7 @@ use helix_view::{ info::Info, input::KeyEvent, keyboard::KeyCode, - tree::{Dimension, Resize}, + tree::{self, Dimension, Resize}, view::View, Document, DocumentId, Editor, ViewId, }; @@ -355,7 +355,7 @@ impl MappableCommand { shrink_buffer_width, "Shrink focused container width", grow_buffer_height, "Grow focused container height", shrink_buffer_height, "Shrink focused container height", - buffer_expand_mode, "Enable expand mode on buffer", + toggle_focus_window, "Toggle focus mode on buffer", goto_line_start, "Goto line start", goto_line_end, "Goto line end", goto_next_buffer, "Goto next buffer", @@ -787,8 +787,8 @@ fn shrink_buffer_height(cx: &mut Context) { cx.editor.resize_buffer(Resize::Shrink, Dimension::Height); } -fn buffer_expand_mode(cx: &mut Context) { - cx.editor.buffer_expand_mode(); +fn toggle_focus_window(cx: &mut Context) { + cx.editor.toggle_focus_window(); } fn goto_next_buffer(cx: &mut Context) { diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 3031c1588..e02959fbd 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -27,11 +27,11 @@ pub fn default() -> HashMap { "end" => goto_line_end, "A-w" => { "Alter Window" - "A-h"|"A-left" => shrink_buffer_width, - "A-l"|"A-right" => grow_buffer_width, - "A-j"|"A-down" => shrink_buffer_height, - "A-k"|"A-up" => grow_buffer_height, - "A-f" => buffer_expand_mode, + "A-h"|"A-left" |"h"|"left" => shrink_buffer_width, + "A-l"|"A-right"|"l"|"right" => grow_buffer_width, + "A-j"|"A-down" |"j"|"down" => shrink_buffer_height, + "A-k"|"A-up" |"k"|"up" => grow_buffer_height, + "A-f"|"f" => toggle_focus_window, }, "A-W" => { "Alter Window" sticky=true @@ -39,7 +39,7 @@ pub fn default() -> HashMap { "l"|"right" => grow_buffer_width, "j"|"down" => shrink_buffer_height, "k"|"up" => grow_buffer_height, - "f" => buffer_expand_mode, + "f" => toggle_focus_window, }, "w" => move_next_word_start, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index f118caa8c..fa3ea90a2 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1649,8 +1649,8 @@ impl Editor { self.tree.resize_buffer(resize_type, dimension); } - pub fn buffer_expand_mode(&mut self) { - self.tree.buffer_expand_mode(); + pub fn toggle_focus_window(&mut self) { + self.tree.toggle_focus_window(); } pub fn should_close(&self) -> bool { diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index afc051eb0..d76005947 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -96,10 +96,10 @@ impl Container { } fn get_child_by_view_id(&mut self, node: ViewId) -> Option<&mut ContainerBounds> { - if let Some(index) = self.children.iter().position(|child| child == &node) { - return self.node_bounds.get_mut(index); - }; - None + self.children + .iter() + .position(|child| child == &node) + .and_then(|index| self.node_bounds.get_mut(index)) } fn push_child(&mut self, node: ViewId) -> &mut Self { @@ -736,7 +736,7 @@ impl Tree { } } - pub fn buffer_expand_mode(&mut self) { + pub fn toggle_focus_window(&mut self) { if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { bounds.expand = !bounds.expand; }