fix resizing breaking cursor
This commit is contained in:
+9
-8
@@ -70,6 +70,9 @@ impl App {
|
|||||||
match event::read().unwrap() {
|
match event::read().unwrap() {
|
||||||
Event::Resize(_, height) => {
|
Event::Resize(_, height) => {
|
||||||
self.window_size.rows = height as usize;
|
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::Key(key_event) => self.handle_key(key_event, terminal),
|
||||||
Event::Mouse(mouse_event) => self.handle_mouse(mouse_event),
|
Event::Mouse(mouse_event) => self.handle_mouse(mouse_event),
|
||||||
@@ -195,21 +198,19 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn yank(&mut self) {
|
fn yank(&mut self) {
|
||||||
self.primary_cursor_register = self.current_buffer()
|
let current_buffer = &self.buffers[self.current_buffer_index];
|
||||||
.contents[self.current_buffer().primary_cursor.range()]
|
|
||||||
|
self.primary_cursor_register = current_buffer
|
||||||
|
.contents[current_buffer.primary_cursor.range()]
|
||||||
.to_vec();
|
.to_vec();
|
||||||
|
|
||||||
self.other_cursor_registers = self.current_buffer().cursors
|
self.other_cursor_registers = current_buffer.cursors
|
||||||
.iter()
|
.iter()
|
||||||
.map(|cursor| {
|
.map(|cursor| {
|
||||||
self.current_buffer().contents[cursor.range()].to_vec()
|
current_buffer.contents[cursor.range()].to_vec()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_buffer(&self) -> &Buffer {
|
|
||||||
&self.buffers[self.current_buffer_index]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowSize {
|
impl WindowSize {
|
||||||
|
|||||||
+4
-2
@@ -3,14 +3,16 @@ use crate::{app::App, buffer::Buffer, custom_greys::CustomGreys};
|
|||||||
|
|
||||||
impl Widget for &App {
|
impl Widget for &App {
|
||||||
fn render(self, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
fn render(self, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||||
|
let current_buffer = &self.buffers[self.current_buffer_index];
|
||||||
|
|
||||||
if self.buffers.len() == 1 {
|
if self.buffers.len() == 1 {
|
||||||
self.current_buffer().render(area, buf);
|
current_buffer.render(area, buf);
|
||||||
} else {
|
} else {
|
||||||
let tab_bar_area = Rect::new(area.x, area.y, area.width, 1);
|
let tab_bar_area = Rect::new(area.x, area.y, area.width, 1);
|
||||||
self.render_tab_bar().render(tab_bar_area, buf);
|
self.render_tab_bar().render(tab_bar_area, buf);
|
||||||
|
|
||||||
let buffer_area = Rect::new(area.x, area.y + 1, area.width, area.height - 1);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -27,8 +27,7 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - inspect selection
|
// - inspect selection
|
||||||
// - resizing can move the cursor off the screen
|
// - diffing
|
||||||
// - tab bar overflow
|
|
||||||
// - search
|
// - search
|
||||||
// - s/A-k/A-K
|
// - s/A-k/A-K
|
||||||
// - C-a/C-x
|
// - 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`
|
// - how to fit??! `-128` longer than `80`
|
||||||
// - popup for different readings for the selected bytes
|
// - popup for different readings for the selected bytes
|
||||||
// - utf8?
|
// - 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() {
|
fn main() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user