diff options
author | Aram Drevekenin <aram@poor.dev> | 2021-11-04 23:19:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-04 23:19:38 +0100 |
commit | 23c97513469fced7298d83bc949c7ca95974a2f6 (patch) | |
tree | 44b34a4e03fbd57fe1a2013d974156c444e17303 | |
parent | f62ccd2a5ce281e710fd315f48d783efef9ea417 (diff) |
fix(resize): do not ignore minimums when doing directional resizes (#838)
* fix(resize): do not ignore minimums when doing directional resizes
* style(fmt): make rustfmt happy
-rw-r--r-- | zellij-server/src/tab.rs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index 5c81b9c6e..4d774b603 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -1625,7 +1625,11 @@ impl Tab { panes_to_the_right.iter().all(|id| { let p = self.panes.get(id).unwrap(); if let Some(cols) = p.position_and_size().cols.as_percent() { + let current_fixed_cols = p.position_and_size().cols.as_usize(); + let will_reduce_by = + ((self.display_area.cols as f64 / 100.0) * increase_by) as usize; cols - increase_by >= RESIZE_PERCENT + && current_fixed_cols.saturating_sub(will_reduce_by) >= p.min_width() } else { false } @@ -1639,7 +1643,11 @@ impl Tab { panes_to_the_left.iter().all(|id| { let p = self.panes.get(id).unwrap(); if let Some(cols) = p.position_and_size().cols.as_percent() { + let current_fixed_cols = p.position_and_size().cols.as_usize(); + let will_reduce_by = + ((self.display_area.cols as f64 / 100.0) * increase_by) as usize; cols - increase_by >= RESIZE_PERCENT + && current_fixed_cols.saturating_sub(will_reduce_by) >= p.min_width() } else { false } @@ -1653,7 +1661,11 @@ impl Tab { panes_below.iter().all(|id| { let p = self.panes.get(id).unwrap(); if let Some(rows) = p.position_and_size().rows.as_percent() { + let current_fixed_rows = p.position_and_size().rows.as_usize(); + let will_reduce_by = + ((self.display_area.rows as f64 / 100.0) * increase_by) as usize; rows - increase_by >= RESIZE_PERCENT + && current_fixed_rows.saturating_sub(will_reduce_by) >= p.min_height() } else { false } @@ -1662,12 +1674,17 @@ impl Tab { false } } + fn can_increase_pane_and_surroundings_up(&self, pane_id: &PaneId, increase_by: f64) -> bool { if let Some(panes_above) = self.pane_ids_directly_above(pane_id) { panes_above.iter().all(|id| { let p = self.panes.get(id).unwrap(); if let Some(rows) = p.position_and_size().rows.as_percent() { + let current_fixed_rows = p.position_and_size().rows.as_usize(); + let will_reduce_by = + ((self.display_area.rows as f64 / 100.0) * increase_by) as usize; rows - increase_by >= RESIZE_PERCENT + && current_fixed_rows.saturating_sub(will_reduce_by) >= p.min_height() } else { false } @@ -1679,9 +1696,13 @@ impl Tab { fn can_reduce_pane_and_surroundings_right(&self, pane_id: &PaneId, reduce_by: f64) -> bool { let pane = self.panes.get(pane_id).unwrap(); if let Some(cols) = pane.position_and_size().cols.as_percent() { + let current_fixed_cols = pane.position_and_size().cols.as_usize(); + let will_reduce_by = ((self.display_area.cols as f64 / 100.0) * reduce_by) as usize; let ids_left = self.pane_ids_directly_left_of(pane_id); let flexible_left = self.ids_are_flexible(Direction::Horizontal, ids_left); - cols - reduce_by >= RESIZE_PERCENT && flexible_left + cols - reduce_by >= RESIZE_PERCENT + && flexible_left + && current_fixed_cols.saturating_sub(will_reduce_by) >= pane.min_width() } else { false } @@ -1689,9 +1710,13 @@ impl Tab { fn can_reduce_pane_and_surroundings_left(&self, pane_id: &PaneId, reduce_by: f64) -> bool { let pane = self.panes.get(pane_id).unwrap(); if let Some(cols) = pane.position_and_size().cols.as_percent() { + let current_fixed_cols = pane.position_and_size().cols.as_usize(); + let will_reduce_by = ((self.display_area.cols as f64 / 100.0) * reduce_by) as usize; let ids_right = self.pane_ids_directly_right_of(pane_id); let flexible_right = self.ids_are_flexible(Direction::Horizontal, ids_right); - cols - reduce_by >= RESIZE_PERCENT && flexible_right + cols - reduce_by >= RESIZE_PERCENT + && flexible_right + && current_fixed_cols.saturating_sub(will_reduce_by) >= pane.min_width() } else { false } @@ -1699,9 +1724,13 @@ impl Tab { fn can_reduce_pane_and_surroundings_down(&self, pane_id: &PaneId, reduce_by: f64) -> bool { let pane = self.panes.get(pane_id).unwrap(); if let Some(rows) = pane.position_and_size().rows.as_percent() { + let current_fixed_rows = pane.position_and_size().rows.as_usize(); + let will_reduce_by = ((self.display_area.rows as f64 / 100.0) * reduce_by) as usize; let ids_above = self.pane_ids_directly_above(pane_id); let flexible_above = self.ids_are_flexible(Direction::Vertical, ids_above); - rows - reduce_by >= RESIZE_PERCENT && flexible_above + rows - reduce_by >= RESIZE_PERCENT + && flexible_above + && current_fixed_rows.saturating_sub(will_reduce_by) >= pane.min_height() } else { false } @@ -1709,9 +1738,13 @@ impl Tab { fn can_reduce_pane_and_surroundings_up(&self, pane_id: &PaneId, reduce_by: f64) -> bool { let pane = self.panes.get(pane_id).unwrap(); if let Some(rows) = pane.position_and_size().rows.as_percent() { + let current_fixed_rows = pane.position_and_size().rows.as_usize(); + let will_reduce_by = ((self.display_area.rows as f64 / 100.0) * reduce_by) as usize; let ids_below = self.pane_ids_directly_below(pane_id); let flexible_below = self.ids_are_flexible(Direction::Vertical, ids_below); - rows - reduce_by >= RESIZE_PERCENT && flexible_below + rows - reduce_by >= RESIZE_PERCENT + && flexible_below + && current_fixed_rows.saturating_sub(will_reduce_by) >= pane.min_height() } else { false } |