Skip to content

Commit

Permalink
mru buffers picker by default, set used_at on editor.switch
Browse files Browse the repository at this point in the history
  • Loading branch information
estin committed Jul 6, 2022
1 parent e845202 commit 6d236c4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ This layer is a kludge of mappings, mostly pickers.
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `b` | Open buffer picker | `buffer_picker` |
| `m` | Open most recent used buffers picker | `mru_buffer_picker` |
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
| `s` | Open document symbol picker (**LSP**) | `symbol_picker` |
| `S` | Open workspace symbol picker (**LSP**) | `workspace_symbol_picker` |
Expand Down
18 changes: 2 additions & 16 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ impl MappableCommand {
file_picker_in_current_directory, "Open file picker at current working directory",
code_action, "Perform code action",
buffer_picker, "Open buffer picker",
mru_buffer_picker, "Open most recent used buffers picker",
symbol_picker, "Open symbol picker",
select_references_to_symbol_under_cursor, "Select symbol references",
workspace_symbol_picker, "Open workspace symbol picker",
Expand Down Expand Up @@ -2192,14 +2191,6 @@ fn file_picker_in_current_directory(cx: &mut Context) {
}

fn buffer_picker(cx: &mut Context) {
_buffer_picker(cx, false);
}

fn mru_buffer_picker(cx: &mut Context) {
_buffer_picker(cx, true);
}

fn _buffer_picker(cx: &mut Context, mru_sort: bool) {
let current = view!(cx.editor).doc;

struct BufferMeta {
Expand Down Expand Up @@ -2255,18 +2246,13 @@ fn _buffer_picker(cx: &mut Context, mru_sort: bool) {
.map(|(_, doc)| new_meta(doc))
.collect::<Vec<BufferMeta>>();

if mru_sort {
items.sort_by(|a, b| b.used_at.cmp(&a.used_at));
}
// mru
items.sort_by(|a, b| b.used_at.cmp(&a.used_at));

let picker = FilePicker::new(
items,
(),
|cx, meta, action| {
// update used_at for mru sorting
if let Some(doc) = cx.editor.documents.get_mut(&meta.id) {
doc.used_at = std::time::Instant::now();
}
cx.editor.switch(meta.id, action);
},
|editor, meta| {
Expand Down
1 change: 0 additions & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ pub fn default() -> HashMap<Mode, Keymap> {
"f" => file_picker,
"F" => file_picker_in_current_directory,
"b" => buffer_picker,
"m" => mru_buffer_picker,
"s" => symbol_picker,
"S" => workspace_symbol_picker,
"g" => diagnostics_picker,
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ impl Editor {
view.last_modified_docs = [Some(view.doc), view.last_modified_docs[0]];
}
}
doc.used_at = std::time::Instant::now();
}

self.replace_document_in_view(view_id, id);
Expand All @@ -796,6 +797,7 @@ impl Editor {
let view_id = view!(self).id;
let doc = self.documents.get_mut(&id).unwrap();
doc.ensure_view_init(view_id);
doc.used_at = std::time::Instant::now();
return;
}
Action::HorizontalSplit | Action::VerticalSplit => {
Expand All @@ -811,6 +813,7 @@ impl Editor {
// initialize selection for view
let doc = self.documents.get_mut(&id).unwrap();
doc.ensure_view_init(view_id);
doc.used_at = std::time::Instant::now();
}
}

Expand Down

0 comments on commit 6d236c4

Please sign in to comment.