Better switcher order
This commit is contained in:
parent
e5916526cb
commit
b4008574cd
3 changed files with 19 additions and 1 deletions
17
src/state.rs
17
src/state.rs
|
|
@ -152,6 +152,7 @@ pub struct Buffer {
|
|||
pub undo: Vec<Change>,
|
||||
pub redo: Vec<Change>,
|
||||
action_counter: usize,
|
||||
most_recent_rank: usize,
|
||||
}
|
||||
|
||||
pub struct Change {
|
||||
|
|
@ -207,6 +208,7 @@ impl Buffer {
|
|||
undo: Vec::new(),
|
||||
redo: Vec::new(),
|
||||
action_counter: 0,
|
||||
most_recent_rank: 0,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -854,6 +856,7 @@ pub struct State {
|
|||
pub buffers: HopSlotMap<BufferId, Buffer>,
|
||||
pub tick: u64,
|
||||
pub theme: theme::Theme,
|
||||
pub most_recent_counter: usize,
|
||||
}
|
||||
|
||||
impl TryFrom<Args> for State {
|
||||
|
|
@ -863,6 +866,7 @@ impl TryFrom<Args> for State {
|
|||
buffers: HopSlotMap::default(),
|
||||
tick: 0,
|
||||
theme: theme::Theme::default(),
|
||||
most_recent_counter: 0,
|
||||
};
|
||||
|
||||
if args.paths.is_empty() {
|
||||
|
|
@ -892,4 +896,17 @@ impl State {
|
|||
pub fn tick(&mut self) {
|
||||
self.tick += 1;
|
||||
}
|
||||
|
||||
pub fn set_most_recent(&mut self, buffer: BufferId) {
|
||||
if let Some(buffer) = self.buffers.get_mut(buffer) {
|
||||
self.most_recent_counter += 1;
|
||||
buffer.most_recent_rank = self.most_recent_counter;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn most_recent(&self) -> Vec<BufferId> {
|
||||
let mut most_recent = self.buffers.keys().collect::<Vec<_>>();
|
||||
most_recent.sort_by_key(|b| core::cmp::Reverse(self.buffers[*b].most_recent_rank));
|
||||
most_recent
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ impl Doc {
|
|||
}
|
||||
|
||||
fn switch_buffer(&mut self, state: &mut State, buffer: BufferId) {
|
||||
state.set_most_recent(buffer);
|
||||
self.buffer = buffer;
|
||||
let Some(buffer) = state.buffers.get_mut(self.buffer) else {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ impl Element<()> for Root {
|
|||
Action::OpenSwitcher => {
|
||||
self.tasks.clear(); // Overrides all
|
||||
self.tasks
|
||||
.push(Task::Switcher(Switcher::new(state.buffers.keys())));
|
||||
.push(Task::Switcher(Switcher::new(state.most_recent())));
|
||||
}
|
||||
Action::OpenOpener(path) => {
|
||||
self.tasks.clear(); // Overrides all
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue