mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix(history): preserve cursor during navigation
This commit is contained in:
parent
77b091aa57
commit
c5658c40c9
1 changed files with 7 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use super::{InputMode, InputSnaps};
|
use super::InputSnaps;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct InputHistory {
|
pub struct InputHistory {
|
||||||
|
|
@ -45,6 +45,7 @@ impl InputHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mode = snaps.current().mode;
|
let mode = snaps.current().mode;
|
||||||
|
let cursor = snaps.current().cursor;
|
||||||
|
|
||||||
// Save current snaps into draft or the slot we're leaving
|
// Save current snaps into draft or the slot we're leaving
|
||||||
let old = mem::take(snaps);
|
let old = mem::take(snaps);
|
||||||
|
|
@ -63,25 +64,18 @@ impl InputHistory {
|
||||||
self.idx = Some(new_idx);
|
self.idx = Some(new_idx);
|
||||||
if self.entry_snaps[new_idx].is_none() {
|
if self.entry_snaps[new_idx].is_none() {
|
||||||
let value = self.entries[new_idx].clone();
|
let value = self.entries[new_idx].clone();
|
||||||
self.entry_snaps[new_idx] = Some(Self::initial_snaps(value, mode, limit));
|
// history does not trigger on obscured inputs
|
||||||
|
self.entry_snaps[new_idx] = Some(InputSnaps::new(value, false, limit));
|
||||||
}
|
}
|
||||||
self.entry_snaps[new_idx].take().unwrap()
|
self.entry_snaps[new_idx].take().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Preserve mode from before navigation
|
// Preserve mode and cursor position from before navigation
|
||||||
let snap = snaps.current_mut();
|
let snap = snaps.current_mut();
|
||||||
snap.cursor = snap.cursor.min(snap.count().saturating_sub(mode.delta()));
|
|
||||||
snap.mode = mode;
|
snap.mode = mode;
|
||||||
|
snap.cursor = cursor.min(snap.count().saturating_sub(mode.delta()));
|
||||||
|
snap.resize(limit);
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_snaps(value: String, mode: InputMode, limit: usize) -> InputSnaps {
|
|
||||||
let mut snaps = InputSnaps::new(value, false, limit);
|
|
||||||
let snap = snaps.current_mut();
|
|
||||||
snap.mode = mode;
|
|
||||||
snap.cursor = snap.count().saturating_sub(mode.delta());
|
|
||||||
snap.resize(limit);
|
|
||||||
snaps
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue