mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-28 12:23:30 +04:00
refactor buffer resize to single function
This commit is contained in:
parent
64311f77df
commit
d8fbff3856
@ -6,7 +6,7 @@
|
||||
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 @@ pub fn transpose_view(&mut self) {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -29,6 +29,16 @@ pub enum Content {
|
||||
Container(Box<Container>),
|
||||
}
|
||||
|
||||
pub enum Resize {
|
||||
Shrink,
|
||||
Grow,
|
||||
}
|
||||
|
||||
pub enum Dimension {
|
||||
Width,
|
||||
Height,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub fn container(layout: Layout) -> Self {
|
||||
Self {
|
||||
@ -687,38 +697,41 @@ fn get_active_node_bounds_mut(
|
||||
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 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_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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user