Better selection in opener

This commit is contained in:
Joshua Barretto 2025-09-23 00:17:39 +01:00
parent 9690c2172d
commit c5e61823f8
2 changed files with 4 additions and 3 deletions

View file

@ -248,11 +248,11 @@ impl Buffer {
self.undo = Vec::new(); self.undo = Vec::new();
} }
pub fn goto_cursor(&mut self, cursor_id: CursorId, pos: [isize; 2], set_base: bool) { pub fn goto_cursor(&mut self, cursor_id: CursorId, coord: [isize; 2], set_base: bool) {
let Some(cursor) = self.cursors.get_mut(cursor_id) else { let Some(cursor) = self.cursors.get_mut(cursor_id) else {
return; return;
}; };
cursor.pos = self.text.to_pos(pos); cursor.pos = self.text.to_pos(coord);
cursor.reset_desired_col(&self.text); cursor.reset_desired_col(&self.text);
if set_base { if set_base {
cursor.base = cursor.pos; cursor.base = cursor.pos;

View file

@ -376,7 +376,8 @@ impl Element<()> for Opener {
match event.to_action(|e| e.to_cancel().or_else(|| e.to_char().map(Action::Char))) { match event.to_action(|e| e.to_cancel().or_else(|| e.to_char().map(Action::Char))) {
Some(Action::Cancel) => Ok(Resp::end(None)), Some(Action::Cancel) => Ok(Resp::end(None)),
// Backspace removes the entire path segment! // Backspace removes the entire path segment!
Some(Action::Char('\x08')) if path_str.ends_with("/") => { // Only works if we're at the end of the string
Some(Action::Char('\x08')) if path_str.ends_with("/") && self.buffer.cursors.get(self.cursor_id).map_or(false, |c| c.selection().is_none() && c.pos == self.buffer.text.chars().len()) => {
if path_str != "/" { if path_str != "/" {
self.set_string( self.set_string(
path_str path_str