click tab bar to go to buffer

This commit is contained in:
alice pellerin
2026-05-16 16:45:14 -05:00
parent 6517de6b61
commit 01a0ab5978
2 changed files with 21 additions and 16 deletions
+21 -15
View File
@@ -198,6 +198,7 @@ impl App {
fn handle_mouse(&mut self, mouse_event: MouseEvent) -> bool { fn handle_mouse(&mut self, mouse_event: MouseEvent) -> bool {
let position = self.mouse_event_position(mouse_event); let position = self.mouse_event_position(mouse_event);
let tab_bar_row_count = u16::from(self.buffers.len() > 1);
let current_buffer = &mut self.buffers[self.current_buffer_index]; let current_buffer = &mut self.buffers[self.current_buffer_index];
match mouse_event.kind { match mouse_event.kind {
@@ -207,6 +208,8 @@ impl App {
current_buffer.cursors.clear(); current_buffer.cursors.clear();
current_buffer.clamp_screen_to_primary_cursor(self.window_size); current_buffer.clamp_screen_to_primary_cursor(self.window_size);
self.is_dragging_mouse = true; self.is_dragging_mouse = true;
} else if mouse_event.row < tab_bar_row_count {
self.switch_to_tab_at(mouse_event.column);
} }
true true
@@ -248,10 +251,10 @@ impl App {
} }
fn mouse_event_position(&self, mouse_event: MouseEvent) -> Option<usize> { fn mouse_event_position(&self, mouse_event: MouseEvent) -> Option<usize> {
let tab_bar_rows = usize::from(self.buffers.len() > 1); let tab_bar_row_count = usize::from(self.buffers.len() > 1);
if usize::from(mouse_event.row) < tab_bar_rows || if usize::from(mouse_event.row) < tab_bar_row_count ||
usize::from(mouse_event.row) - tab_bar_rows >= self.window_size.hex_rows() { usize::from(mouse_event.row) - tab_bar_row_count >= self.window_size.hex_rows() {
return None; return None;
} }
@@ -283,20 +286,23 @@ impl App {
byte_column.map(|byte_column| { byte_column.map(|byte_column| {
current_buffer.scroll_position + current_buffer.scroll_position +
(mouse_event.row as usize - tab_bar_rows) * BYTES_PER_LINE + (mouse_event.row as usize - tab_bar_row_count) * BYTES_PER_LINE +
byte_column byte_column
}) })
}
// if let Some(byte_column) = byte_column && fn switch_to_tab_at(&mut self, column: u16) {
// mouse_event.row as usize - tab_bar_rows < self.window_size.hex_rows() let mut column: usize = column.into();
// {
// Some( for buffer_index in 0..self.buffers.len() {
// current_buffer.scroll_position + let tab_width = self.buffers[buffer_index].file_name.len() + 2;
// (mouse_event.row as usize - tab_bar_rows) * BYTES_PER_LINE +
// byte_column if column < tab_width {
// ) self.current_buffer_index = buffer_index;
// } else { return;
// None }
// }
column -= tab_width;
}
} }
} }
-1
View File
@@ -1,7 +1,6 @@
# todo # todo
- v1.0 - v1.0
- `T` Till - `T` Till
- click on tab to go to buffer
- `go` goto entered offset - `go` goto entered offset
- search - search
- `/` hex, `A-/` ASCII - `/` hex, `A-/` ASCII