From 64311f77dfa54b343f76397cb1ced3df239320d6 Mon Sep 17 00:00:00 2001 From: Termina94 Date: Tue, 7 Jun 2022 22:21:50 +0100 Subject: [PATCH 1/6] Add flex resize, focus mode, hard-coded limits for now --- helix-term/src/commands.rs | 24 ++++ helix-term/src/keymap/default.rs | 8 ++ helix-view/src/editor.rs | 20 ++++ helix-view/src/tree.rs | 188 +++++++++++++++++++++++++++++-- 4 files changed, 228 insertions(+), 12 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 75df430a3..cdba93f5f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -351,6 +351,11 @@ impl MappableCommand { goto_prev_change, "Goto previous change", goto_first_change, "Goto first change", goto_last_change, "Goto last change", + grow_buffer_width, "Grow focused container width", + shrink_buffer_width, "Shrink focused container width", + grow_buffer_height, "Grow focused container height", + shrink_buffer_height, "Shrink focused container height", + buffer_focus_mode, "Enable focus mode on buffer", goto_line_start, "Goto line start", goto_line_end, "Goto line end", goto_next_buffer, "Goto next buffer", @@ -767,6 +772,25 @@ fn goto_line_start(cx: &mut Context) { ) } +fn grow_buffer_width(cx: &mut Context) { + cx.editor.grow_buffer_width(); +} + +fn shrink_buffer_width(cx: &mut Context) { + cx.editor.shrink_buffer_width(); +} +fn grow_buffer_height(cx: &mut Context) { + cx.editor.grow_buffer_height(); +} + +fn shrink_buffer_height(cx: &mut Context) { + cx.editor.shrink_buffer_height(); +} + +fn buffer_focus_mode(cx: &mut Context) { + cx.editor.buffer_focus_mode(); +} + fn goto_next_buffer(cx: &mut Context) { goto_buffer(cx.editor, Direction::Forward); } diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 763ed4ae7..849bbabfc 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -26,6 +26,14 @@ pub fn default() -> HashMap { "home" => goto_line_start, "end" => goto_line_end, + "A-w" => { "Alter Window" + "A-w"|"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_focus_mode, + }, + "w" => move_next_word_start, "b" => move_prev_word_start, "e" => move_next_word_end, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 7af28ccc6..e50069fdd 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1645,6 +1645,26 @@ impl Editor { self.tree.transpose(); } + pub fn grow_buffer_width(&mut self) { + self.tree.grow_buffer_width(); + } + + pub fn shrink_buffer_width(&mut self) { + self.tree.shrink_buffer_width(); + } + + pub fn grow_buffer_height(&mut self) { + self.tree.grow_buffer_height(); + } + + pub fn shrink_buffer_height(&mut self) { + self.tree.shrink_buffer_height(); + } + + pub fn buffer_focus_mode(&mut self) { + self.tree.buffer_focus_mode(); + } + pub fn should_close(&self) -> bool { self.tree.is_empty() } diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index 4c9eba0fd..7c687dafe 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -65,6 +65,14 @@ pub struct Container { layout: Layout, children: Vec, area: Rect, + node_bounds: Vec, +} + +#[derive(Debug, Clone, Copy)] +pub struct ContainerBounds { + width: usize, + height: usize, + focus: bool, } impl Container { @@ -73,8 +81,80 @@ impl Container { layout, children: Vec::new(), area: Rect::default(), + node_bounds: Vec::new(), } } + + 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 + } + + fn push_child(&mut self, node: ViewId) -> &mut Self { + self.children.push(node); + self.add_child_bounds(); + self + } + + fn insert_child(&mut self, index: usize, node: ViewId) -> &mut Self { + self.children.insert(index, node); + self.insert_child_bounds(index); + self + } + + fn remove_child(&mut self, index: usize) -> &mut Self { + self.children.remove(index); + self.remove_child_bounds(index); + self + } + + fn add_child_bounds(&mut self) -> &mut Self { + self.node_bounds.push(ContainerBounds { + width: 10, + height: 10, + focus: false, + }); + self + } + + fn insert_child_bounds(&mut self, index: usize) -> &mut Self { + self.node_bounds.insert( + index, + ContainerBounds { + width: 10, + height: 10, + focus: false, + }, + ); + self + } + + fn remove_child_bounds(&mut self, index: usize) -> &mut Self { + self.node_bounds.remove(index); + self + } + + fn calculate_slots_width(&self) -> usize { + self.node_bounds + .iter() + .map(|bounds| match bounds.focus { + true => 40, + false => bounds.width, + }) + .sum() + } + + fn calculate_slots_height(&self) -> usize { + self.node_bounds + .iter() + .map(|bounds| match bounds.focus { + true => 40, + false => bounds.height, + }) + .sum() + } } impl Default for Container { @@ -131,7 +211,7 @@ impl Tree { pos + 1 }; - container.children.insert(pos, node); + container.insert_child(pos, node); // focus the new node self.focus = node; @@ -168,7 +248,7 @@ impl Tree { .unwrap(); pos + 1 }; - container.children.insert(pos, node); + container.insert_child(pos, node); self.nodes[node].parent = parent; } else { let mut split = Node::container(layout); @@ -182,8 +262,8 @@ impl Tree { } => container, _ => unreachable!(), }; - container.children.push(focus); - container.children.push(node); + container.push_child(focus); + container.push_child(node); self.nodes[focus].parent = split; self.nodes[node].parent = split; @@ -359,12 +439,17 @@ impl Tree { match container.layout { Layout::Horizontal => { let len = container.children.len(); - - let height = area.height / len as u16; - + let slots = container.calculate_slots_height(); + let slot_height = area.height as f32 / slots as f32; let mut child_y = area.y; for (i, child) in container.children.iter().enumerate() { + let bounds = container.node_bounds[i]; + let height = match bounds.focus { + true => (40.0 * slot_height) as u16, + false => (slot_height * bounds.height as f32).floor() as u16, + }; + let mut area = Rect::new( container.area.x, child_y, @@ -373,7 +458,7 @@ impl Tree { ); child_y += height; - // last child takes the remaining width because we can get uneven + // last child takes the remaining height because we can get uneven // space from rounding if i == len - 1 { area.height = container.area.y + container.area.height - area.y; @@ -384,15 +469,20 @@ impl Tree { } Layout::Vertical => { let len = container.children.len(); - - let width = area.width / len as u16; + let slots = container.calculate_slots_width(); + let slot_width: f32 = area.width as f32 / slots as f32; + let mut child_x = area.x; let inner_gap = 1u16; // let total_gap = inner_gap * (len as u16 - 1); - let mut child_x = area.x; - for (i, child) in container.children.iter().enumerate() { + let bounds = container.node_bounds[i]; + let width = match bounds.focus { + true => (40.0 * slot_width) as u16, + false => (slot_width * bounds.width as f32).floor() as u16, + }; + let mut area = Rect::new( child_x, container.area.y, @@ -571,6 +661,80 @@ impl Tree { } } + fn get_active_node_bounds_mut( + &mut self, + expect_layout: Layout, + ) -> Option<&mut ContainerBounds> { + let mut focus = self.focus; + let mut parent = self.nodes[focus].parent; + + // Parent expected to be container + if let Some(focused_layout) = match &self.nodes[parent].content { + Content::View(_) => unreachable!(), + Content::Container(node) => Some(node.layout), + } { + // if we want to make a width change and we have a `Horizontal` layout focused, + // alter the parent `Vertical` layout instead and vice versa + if focused_layout != expect_layout { + focus = parent; + parent = self.nodes[parent].parent; + } + + if let Content::Container(node) = &mut self.nodes[parent].content { + return node.as_mut().get_child_by_view_id(focus); + }; + } + None + } + + pub fn grow_buffer_width(&mut self) { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { + if bounds.width < 20 { + bounds.width += 1; + self.recalculate(); + } + } + } + + pub fn shrink_buffer_width(&mut self) { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { + if bounds.width > 1 { + bounds.width -= 1; + self.recalculate(); + } + } + } + + pub fn grow_buffer_height(&mut self) { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { + if bounds.height < 20 { + bounds.height += 1; + self.recalculate(); + } + } + } + + pub fn shrink_buffer_height(&mut self) { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { + if bounds.height > 1 { + bounds.height -= 1; + self.recalculate(); + } + } + } + + pub fn buffer_focus_mode(&mut self) { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { + bounds.focus = !bounds.focus; + } + + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { + bounds.focus = !bounds.focus; + } + + self.recalculate(); + } + pub fn swap_split_in_direction(&mut self, direction: Direction) -> Option<()> { let focus = self.focus; let target = self.find_split_in_direction(focus, direction)?; From d8fbff38562c770b435e6229c15e78dd635fd4c9 Mon Sep 17 00:00:00 2001 From: Termina94 Date: Tue, 12 Jul 2022 21:56:52 +0100 Subject: [PATCH 2/6] refactor buffer resize to single function --- helix-view/src/editor.rs | 10 +++--- helix-view/src/tree.rs | 75 +++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index e50069fdd..900b330b5 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -6,7 +6,7 @@ use crate::{ input::KeyEvent, register::Registers, theme::{self, Theme}, - tree::{self, Tree}, + tree::{self, Dimension, Resize, Tree}, view::ViewPosition, Align, Document, DocumentId, View, ViewId, }; @@ -1646,19 +1646,19 @@ impl Editor { } pub fn grow_buffer_width(&mut self) { - self.tree.grow_buffer_width(); + self.tree.resize_buffer(Resize::Grow, Dimension::Width); } pub fn shrink_buffer_width(&mut self) { - self.tree.shrink_buffer_width(); + self.tree.resize_buffer(Resize::Shrink, Dimension::Width); } pub fn grow_buffer_height(&mut self) { - self.tree.grow_buffer_height(); + self.tree.resize_buffer(Resize::Grow, Dimension::Height); } pub fn shrink_buffer_height(&mut self) { - self.tree.shrink_buffer_height(); + self.tree.resize_buffer(Resize::Shrink, Dimension::Height); } pub fn buffer_focus_mode(&mut self) { diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index 7c687dafe..aa7de6a5d 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -29,6 +29,16 @@ pub enum Content { Container(Box), } +pub enum Resize { + Shrink, + Grow, +} + +pub enum Dimension { + Width, + Height, +} + impl Node { pub fn container(layout: Layout) -> Self { Self { @@ -687,38 +697,41 @@ impl Tree { None } - pub fn grow_buffer_width(&mut self) { - if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { - if bounds.width < 20 { - bounds.width += 1; - self.recalculate(); - } - } - } - - pub fn shrink_buffer_width(&mut self) { - if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { - if bounds.width > 1 { - bounds.width -= 1; - self.recalculate(); - } - } - } - - pub fn grow_buffer_height(&mut self) { - if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { - if bounds.height < 20 { - bounds.height += 1; - self.recalculate(); + pub fn resize_buffer(&mut self, resize_type: Resize, dimension: Dimension) { + match dimension { + Dimension::Width => { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { + match resize_type { + Resize::Shrink => { + if bounds.width > 1 { + bounds.width -= 1; + } + } + Resize::Grow => { + if bounds.width < 20 { + bounds.width += 1; + } + } + }; + self.recalculate(); + } } - } - } - - pub fn shrink_buffer_height(&mut self) { - if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { - if bounds.height > 1 { - bounds.height -= 1; - self.recalculate(); + Dimension::Height => { + if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { + match resize_type { + Resize::Shrink => { + if bounds.height > 1 { + bounds.height -= 1; + } + } + Resize::Grow => { + if bounds.height < 20 { + bounds.height += 1; + } + } + }; + self.recalculate(); + } } } } From e4c90548e15d91549e7930076ce2d933210ea387 Mon Sep 17 00:00:00 2001 From: Termina94 Date: Tue, 12 Jul 2022 22:05:22 +0100 Subject: [PATCH 3/6] rename focus to expand --- helix-term/src/commands.rs | 6 +++--- helix-term/src/keymap/default.rs | 2 +- helix-view/src/editor.rs | 4 ++-- helix-view/src/tree.rs | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cdba93f5f..ff906fef5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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_focus_mode, "Enable focus mode on buffer", + buffer_expand_mode, "Enable expand 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.shrink_buffer_height(); } -fn buffer_focus_mode(cx: &mut Context) { - cx.editor.buffer_focus_mode(); +fn buffer_expand_mode(cx: &mut Context) { + cx.editor.buffer_expand_mode(); } fn goto_next_buffer(cx: &mut Context) { diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 849bbabfc..47182a04b 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -31,7 +31,7 @@ pub fn default() -> HashMap { "A-l"|"A-right" => grow_buffer_width, "A-j"|"A-down" => shrink_buffer_height, "A-k"|"A-up" => grow_buffer_height, - "A-f" => buffer_focus_mode, + "A-f" => buffer_expand_mode, }, "w" => move_next_word_start, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 900b330b5..03753345c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1661,8 +1661,8 @@ impl Editor { self.tree.resize_buffer(Resize::Shrink, Dimension::Height); } - pub fn buffer_focus_mode(&mut self) { - self.tree.buffer_focus_mode(); + pub fn buffer_expand_mode(&mut self) { + self.tree.buffer_expand_mode(); } pub fn should_close(&self) -> bool { diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index aa7de6a5d..afc051eb0 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -82,7 +82,7 @@ pub struct Container { pub struct ContainerBounds { width: usize, height: usize, - focus: bool, + expand: bool, } impl Container { @@ -124,7 +124,7 @@ impl Container { self.node_bounds.push(ContainerBounds { width: 10, height: 10, - focus: false, + expand: false, }); self } @@ -135,7 +135,7 @@ impl Container { ContainerBounds { width: 10, height: 10, - focus: false, + expand: false, }, ); self @@ -149,7 +149,7 @@ impl Container { fn calculate_slots_width(&self) -> usize { self.node_bounds .iter() - .map(|bounds| match bounds.focus { + .map(|bounds| match bounds.expand { true => 40, false => bounds.width, }) @@ -159,7 +159,7 @@ impl Container { fn calculate_slots_height(&self) -> usize { self.node_bounds .iter() - .map(|bounds| match bounds.focus { + .map(|bounds| match bounds.expand { true => 40, false => bounds.height, }) @@ -455,7 +455,7 @@ impl Tree { for (i, child) in container.children.iter().enumerate() { let bounds = container.node_bounds[i]; - let height = match bounds.focus { + let height = match bounds.expand { true => (40.0 * slot_height) as u16, false => (slot_height * bounds.height as f32).floor() as u16, }; @@ -488,7 +488,7 @@ impl Tree { for (i, child) in container.children.iter().enumerate() { let bounds = container.node_bounds[i]; - let width = match bounds.focus { + let width = match bounds.expand { true => (40.0 * slot_width) as u16, false => (slot_width * bounds.width as f32).floor() as u16, }; @@ -736,13 +736,13 @@ impl Tree { } } - pub fn buffer_focus_mode(&mut self) { + pub fn buffer_expand_mode(&mut self) { if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Horizontal) { - bounds.focus = !bounds.focus; + bounds.expand = !bounds.expand; } if let Some(bounds) = self.get_active_node_bounds_mut(Layout::Vertical) { - bounds.focus = !bounds.focus; + bounds.expand = !bounds.expand; } self.recalculate(); From 689101424100a6c810355b0e4925ed8feb14f30a Mon Sep 17 00:00:00 2001 From: Termina94 Date: Tue, 12 Jul 2022 22:33:34 +0100 Subject: [PATCH 4/6] refactor editor resize functions --- helix-term/src/commands.rs | 10 +++++----- helix-view/src/editor.rs | 16 ++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ff906fef5..592ef5260 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, + tree::{Dimension, Resize}, view::View, Document, DocumentId, Editor, ViewId, }; @@ -773,18 +773,18 @@ fn goto_line_start(cx: &mut Context) { } fn grow_buffer_width(cx: &mut Context) { - cx.editor.grow_buffer_width(); + cx.editor.resize_buffer(Resize::Grow, Dimension::Width); } fn shrink_buffer_width(cx: &mut Context) { - cx.editor.shrink_buffer_width(); + cx.editor.resize_buffer(Resize::Shrink, Dimension::Width); } fn grow_buffer_height(cx: &mut Context) { - cx.editor.grow_buffer_height(); + cx.editor.resize_buffer(Resize::Grow, Dimension::Height); } fn shrink_buffer_height(cx: &mut Context) { - cx.editor.shrink_buffer_height(); + cx.editor.resize_buffer(Resize::Shrink, Dimension::Height); } fn buffer_expand_mode(cx: &mut Context) { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 03753345c..f118caa8c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1645,20 +1645,8 @@ impl Editor { self.tree.transpose(); } - pub fn grow_buffer_width(&mut self) { - self.tree.resize_buffer(Resize::Grow, Dimension::Width); - } - - pub fn shrink_buffer_width(&mut self) { - self.tree.resize_buffer(Resize::Shrink, Dimension::Width); - } - - pub fn grow_buffer_height(&mut self) { - self.tree.resize_buffer(Resize::Grow, Dimension::Height); - } - - pub fn shrink_buffer_height(&mut self) { - self.tree.resize_buffer(Resize::Shrink, Dimension::Height); + pub fn resize_buffer(&mut self, resize_type: Resize, dimension: Dimension) { + self.tree.resize_buffer(resize_type, dimension); } pub fn buffer_expand_mode(&mut self) { From 5aaaf137cbe4dd358e7f81d259fec1722856f69f Mon Sep 17 00:00:00 2001 From: Termina94 Date: Thu, 21 Jul 2022 19:11:24 +0100 Subject: [PATCH 5/6] add sticky mode for 'alter window' pane --- helix-term/src/keymap/default.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 47182a04b..3031c1588 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -27,13 +27,21 @@ pub fn default() -> HashMap { "end" => goto_line_end, "A-w" => { "Alter Window" - "A-w"|"A-left" => shrink_buffer_width, + "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-W" => { "Alter Window" sticky=true + "h"|"left" => shrink_buffer_width, + "l"|"right" => grow_buffer_width, + "j"|"down" => shrink_buffer_height, + "k"|"up" => grow_buffer_height, + "f" => buffer_expand_mode, + }, + "w" => move_next_word_start, "b" => move_prev_word_start, "e" => move_next_word_end, From 978c1a126d77aba03120bcca2a98e31639120416 Mon Sep 17 00:00:00 2001 From: sander777 Date: Mon, 23 Oct 2023 18:56:00 +0300 Subject: [PATCH 6/6] 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; }