Fix sporadic cursor jumps (a bit hacky) (#753)

* Fix occasional sporadic cursor movements

* Discern between "editor" and "message" windows
macos-click-through
Nigel Baillie 3 years ago committed by GitHub
parent 55e7d15fad
commit 27a9c94ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -242,6 +242,7 @@ impl Editor {
} else {
let window = Window::new(
grid,
WindowType::Editor,
width,
height,
None,
@ -267,6 +268,7 @@ impl Editor {
} else {
let new_window = Window::new(
grid,
WindowType::Editor,
width,
height,
None,
@ -334,6 +336,7 @@ impl Editor {
};
if let Some(window) = self.windows.get_mut(&grid) {
window.window_type = WindowType::Message;
window.position(
parent_width,
window.get_height(),
@ -345,6 +348,7 @@ impl Editor {
} else {
let new_window = Window::new(
grid,
WindowType::Message,
parent_width,
1,
Some(anchor_info),
@ -383,6 +387,28 @@ impl Editor {
}
fn set_cursor_position(&mut self, grid: u64, grid_left: u64, grid_top: u64) {
match self.windows.get(&grid) {
Some(Window { window_type: WindowType::Message, .. }) => {
// When the user presses ":" to type a command, the cursor is sent to the gutter
// in position 1 (right after the ":"). In all other cases, we want to skip
// positioning to avoid confusing movements.
let intentional = grid_left == 1;
// If the cursor was already in this message, we can still move within it.
let already_there = self.cursor.parent_window_id == grid;
if !intentional && !already_there {
trace!(
"Cursor unexpectedly sent to message buffer {} ({}, {})",
grid,
grid_left,
grid_top
);
return;
}
}
_ => {}
}
self.cursor.parent_window_id = grid;
self.cursor.grid_position = (grid_left, grid_top);
}

@ -43,9 +43,15 @@ pub enum WindowDrawCommand {
},
}
pub enum WindowType {
Editor,
Message
}
pub struct Window {
grid_id: u64,
grid: CharacterGrid,
pub window_type: WindowType,
pub anchor_info: Option<AnchorInfo>,
@ -58,6 +64,7 @@ pub struct Window {
impl Window {
pub fn new(
grid_id: u64,
window_type: WindowType,
width: u64,
height: u64,
anchor_info: Option<AnchorInfo>,
@ -68,6 +75,7 @@ impl Window {
let window = Window {
grid_id,
grid: CharacterGrid::new((width, height)),
window_type,
anchor_info,
grid_left,
grid_top,
@ -370,7 +378,9 @@ mod tests {
#[test]
fn window_separator_modifies_grid_and_sends_draw_command() {
let (batched_receiver, batched_sender) = build_test_channels();
let mut window = Window::new(1, 114, 64, None, 0.0, 0.0, batched_sender.clone());
let mut window = Window::new(
1, WindowType::Editor, 114, 64, None, 0.0, 0.0, batched_sender.clone()
);
batched_sender
.send_batch()
.expect("Could not send batch of commands");

Loading…
Cancel
Save