From 9e61bf396e56b385c274e64f8daf96b78e9ed8de Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Sat, 21 Mar 2026 22:37:29 -0500 Subject: [PATCH] fix resizing breaking cursor --- src/app/mod.rs | 17 +++++++++-------- src/app/widget.rs | 6 ++++-- src/main.rs | 7 +++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 4cadbfa..bd4faaf 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -70,6 +70,9 @@ impl App { match event::read().unwrap() { Event::Resize(_, height) => { self.window_size.rows = height as usize; + + self.buffers[self.current_buffer_index] + .clamp_screen_to_primary_cursor(self.window_size); } Event::Key(key_event) => self.handle_key(key_event, terminal), Event::Mouse(mouse_event) => self.handle_mouse(mouse_event), @@ -195,21 +198,19 @@ impl App { } fn yank(&mut self) { - self.primary_cursor_register = self.current_buffer() - .contents[self.current_buffer().primary_cursor.range()] + let current_buffer = &self.buffers[self.current_buffer_index]; + + self.primary_cursor_register = current_buffer + .contents[current_buffer.primary_cursor.range()] .to_vec(); - self.other_cursor_registers = self.current_buffer().cursors + self.other_cursor_registers = current_buffer.cursors .iter() .map(|cursor| { - self.current_buffer().contents[cursor.range()].to_vec() + current_buffer.contents[cursor.range()].to_vec() }) .collect(); } - - pub fn current_buffer(&self) -> &Buffer { - &self.buffers[self.current_buffer_index] - } } impl WindowSize { diff --git a/src/app/widget.rs b/src/app/widget.rs index 8d5b78f..5d68471 100644 --- a/src/app/widget.rs +++ b/src/app/widget.rs @@ -3,14 +3,16 @@ use crate::{app::App, buffer::Buffer, custom_greys::CustomGreys}; impl Widget for &App { fn render(self, area: Rect, buf: &mut ratatui::buffer::Buffer) { + let current_buffer = &self.buffers[self.current_buffer_index]; + if self.buffers.len() == 1 { - self.current_buffer().render(area, buf); + current_buffer.render(area, buf); } else { let tab_bar_area = Rect::new(area.x, area.y, area.width, 1); self.render_tab_bar().render(tab_bar_area, buf); let buffer_area = Rect::new(area.x, area.y + 1, area.width, area.height - 1); - self.current_buffer().render(buffer_area, buf); + current_buffer.render(buffer_area, buf); } } } diff --git a/src/main.rs b/src/main.rs index d1a5fc3..44c8dd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,7 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // TODO: // - inspect selection -// - resizing can move the cursor off the screen -// - tab bar overflow +// - diffing // - search // - s/A-k/A-K // - C-a/C-x @@ -53,9 +52,9 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - how to fit??! `-128` longer than `80` // - popup for different readings for the selected bytes // - utf8? -// - diffing -// when AsciiChar is stabilized, use it instead of char everywhere +// when AsciiChar is stabilized, use it instead of char +// - actually since im using nightly already, do this fn main() { let mut app = App::new();