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();
}
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 {
return;
};
cursor.pos = self.text.to_pos(pos);
cursor.pos = self.text.to_pos(coord);
cursor.reset_desired_col(&self.text);
if set_base {
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))) {
Some(Action::Cancel) => Ok(Resp::end(None)),
// 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 != "/" {
self.set_string(
path_str