diff options
author | Evgeniy Tatarkin | 2023-04-28 16:05:14 +0000 |
---|---|---|
committer | GitHub | 2023-04-28 16:05:14 +0000 |
commit | 6a1bb81f1022533c226395aaa41439ab1ea41dd4 (patch) | |
tree | 2886a0c1f21edd9ada66dcf5341d4eb3626b6928 /helix-term | |
parent | 9c6c63a2be30252a6207f4aebb5e0f76f746b4c8 (diff) |
Sort the buffer picker by most recent access (#2980)
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 18 |
1 files changed, 13 insertions, 5 deletions
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<PathBuf>, 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::<Vec<BufferMeta>>(); + + // 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); |