From 6a1bb81f1022533c226395aaa41439ab1ea41dd4 Mon Sep 17 00:00:00 2001 From: Evgeniy Tatarkin Date: Fri, 28 Apr 2023 19:05:14 +0300 Subject: Sort the buffer picker by most recent access (#2980) --- helix-term/src/commands.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'helix-term/src/commands.rs') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5a75553c..88393ff4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2473,6 +2473,7 @@ fn buffer_picker(cx: &mut Context) { path: Option, is_modified: bool, is_current: bool, + focused_at: std::time::Instant, } impl ui::menu::Item for BufferMeta { @@ -2505,14 +2506,21 @@ fn buffer_picker(cx: &mut Context) { path: doc.path().cloned(), is_modified: doc.is_modified(), is_current: doc.id() == current, + focused_at: doc.focused_at, }; + let mut items = cx + .editor + .documents + .values() + .map(|doc| new_meta(doc)) + .collect::>(); + + // mru + items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at)); + let picker = FilePicker::new( - cx.editor - .documents - .values() - .map(|doc| new_meta(doc)) - .collect(), + items, (), |cx, meta, action| { cx.editor.switch(meta.id, action); -- cgit v1.2.3-70-g09d2