From b0ff230588bed369d8338c240788d548eff2704f Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 23 Apr 2025 22:18:40 +0800 Subject: [PATCH] table: Disable auto scroll when resize column out of the table right bounds. (#811) https://github.com/user-attachments/assets/f1569eb5-e6e6-43f9-9425-0de5e2235163 Do same behavior like the macOS table. --- crates/ui/src/table.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ui/src/table.rs b/crates/ui/src/table.rs index ca376790..ab4ce55f 100644 --- a/crates/ui/src/table.rs +++ b/crates/ui/src/table.rs @@ -652,17 +652,20 @@ where /// Scroll table when mouse position is near the edge of the table bounds. fn scroll_table_by_col_resizing( &mut self, - pos: Point, + mouse_position: Point, col_group: ColGroup, - _window: &mut Window, - _cx: &mut Context, ) { + // Do nothing if pos out of the table bounds right for avoid scroll to the right. + if mouse_position.x > self.bounds.right() { + return; + } + let mut offset = self.horizontal_scroll_handle.offset(); let col_bounds = col_group.bounds; - if pos.x < self.bounds.left() && col_bounds.right() < self.bounds.left() + px(20.) { + if mouse_position.x < self.bounds.left() && col_bounds.right() < self.bounds.left() + px(20.) { offset.x += px(1.); - } else if pos.x > self.bounds.right() && col_bounds.right() > self.bounds.right() - px(20.) + } else if mouse_position.x > self.bounds.right() && col_bounds.right() > self.bounds.right() - px(20.) { offset.x -= px(1.); } @@ -973,8 +976,6 @@ where view.scroll_table_by_col_resizing( e.event.position, col_group, - window, - cx, ); } };