Skip to content

Commit

Permalink
don't resize pane with delta
Browse files Browse the repository at this point in the history
say the pane with 100 cols wide, we got 3 mouse events, one move the
split to 99, the next one move it to 98, then to 90

we would first call resize_split_by with -1, -1, then with -8. the first
resize is completed just as we call resize_split_by(-8), this triggers a
resync, and updates the split position to 99. because of that
resize_split_by(-8) will try to resize it to 91, instead of the desire
90.

in practice, there are a lot more mouse events and the timing is more
unpredictable, the end result can be very chaotic.

partially fix #5142
  • Loading branch information
yshui committed Aug 30, 2024
1 parent 30345b3 commit 9b7a29b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 9 additions & 11 deletions mux/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ impl Tab {
/// Called when running in the mux server after an individual pane
/// has been resized.
/// Because the split manipulation happened on the GUI we "lost"
/// the information that would have allowed us to call resize_split_by()
/// the information that would have allowed us to call resize_split_to()
/// and instead need to back-infer the split size information.
/// We rely on the client to have resized (or be in the process
/// of resizing) affected panes consistently with its own Tab
Expand All @@ -636,8 +636,8 @@ impl Tab {
/// and negative values to the left/top.
/// The adjusted size is propogated downwards to contained children and
/// their panes are resized accordingly.
pub fn resize_split_by(&self, split_index: usize, delta: isize) {
self.inner.lock().resize_split_by(split_index, delta)
pub fn resize_split_to(&self, split_index: usize, left_or_top: isize) {
self.inner.lock().resize_split_to(split_index, left_or_top)
}

/// Adjusts the size of the active pane in the specified direction
Expand Down Expand Up @@ -1258,7 +1258,7 @@ impl TabInner {
Mux::try_get().map(|mux| mux.notify(MuxNotification::TabResized(self.id)));
}

fn resize_split_by(&mut self, split_index: usize, delta: isize) {
fn resize_split_to(&mut self, split_index: usize, left_or_top: isize) {
if self.zoomed.is_some() {
return;
}
Expand Down Expand Up @@ -1286,21 +1286,20 @@ impl TabInner {
}

// Now cursor is looking at the split
self.adjust_node_at_cursor(&mut cursor, delta);
self.adjust_node_at_cursor(&mut cursor, left_or_top);
self.cascade_size_from_cursor(cursor);
Mux::try_get().map(|mux| mux.notify(MuxNotification::TabResized(self.id)));
}

fn adjust_node_at_cursor(&mut self, cursor: &mut Cursor, delta: isize) {
fn adjust_node_at_cursor(&mut self, cursor: &mut Cursor, left_or_top: isize) {
let cell_dimensions = self.cell_dimensions();
if let Ok(Some(node)) = cursor.node_mut() {
match node.direction {
SplitDirection::Horizontal => {
let width = node.width();

let mut cols = node.first.cols as isize;
cols = cols
.saturating_add(delta)
cols = left_or_top
.max(1)
.min((width as isize).saturating_sub(2));
node.first.cols = cols as usize;
Expand All @@ -1315,8 +1314,7 @@ impl TabInner {
let height = node.height();

let mut rows = node.first.rows as isize;
rows = rows
.saturating_add(delta)
rows = left_or_top
.max(1)
.min((height as isize).saturating_sub(2));
node.first.rows = rows as usize;
Expand Down Expand Up @@ -2494,7 +2492,7 @@ mod test {
assert_eq!(600, panes[2].pixel_height);
assert_eq!(2, panes[2].pane.pane_id());

tab.resize_split_by(1, 1);
tab.resize_split_to(1, 1);
let panes = tab.iter_panes();
assert_eq!(39, panes[0].width);
assert_eq!(12, panes[0].height);
Expand Down
10 changes: 5 additions & 5 deletions wezterm-gui/src/termwindow/mouseevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ impl super::TermWindow {
Some(tab) => tab,
None => return,
};
let delta = match split.direction {
SplitDirection::Horizontal => (x as isize).saturating_sub(split.left as isize),
SplitDirection::Vertical => (y as isize).saturating_sub(split.top as isize),
let (left_or_top, changed) = match split.direction {
SplitDirection::Horizontal => (x as isize, split.left as isize != x as isize),
SplitDirection::Vertical => (y as isize, split.top as isize != y as isize),
};

if delta != 0 {
tab.resize_split_by(split.index, delta);
if changed {
tab.resize_split_to(split.index, left_or_top);
if let Some(split) = tab.iter_splits().into_iter().nth(split.index) {
item.item_type = UIItemType::Split(split);
context.invalidate();
Expand Down

0 comments on commit 9b7a29b

Please sign in to comment.