From 21546f623204012eb4b1b8f9f62fff292992bbf5 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:26:22 +0000 Subject: [PATCH 1/2] feat: add command to see edited buffers --- helix-term/src/commands.rs | 17 ++++++++++++++++- helix-term/src/keymap/default.rs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ee2949fa0..aa2ad099b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -377,6 +377,7 @@ pub fn doc(&self) -> &str { file_picker_in_current_directory, "Open file picker at current working directory", code_action, "Perform code action", buffer_picker, "Open buffer picker", + modified_buffer_picker, "Open buffer picker for modified buffers", jumplist_picker, "Open jumplist picker", symbol_picker, "Open symbol picker", changed_file_picker, "Open changed file picker", @@ -2948,7 +2949,7 @@ fn file_picker_in_current_directory(cx: &mut Context) { cx.push_layer(Box::new(overlaid(picker))); } -fn buffer_picker(cx: &mut Context) { +fn buffer_picker_impl(cx: &mut Context, only_modified: bool) { let current = view!(cx.editor).doc; struct BufferMeta { @@ -2972,8 +2973,14 @@ struct BufferMeta { .documents .values() .map(new_meta) + .filter(|buf| if only_modified { buf.is_modified } else { true }) .collect::>(); + if only_modified && items.len() == 0 { + cx.editor.set_status("No buffers modified"); + return; + } + // mru items.sort_unstable_by_key(|item| std::cmp::Reverse(item.focused_at)); @@ -3016,6 +3023,14 @@ struct BufferMeta { cx.push_layer(Box::new(overlaid(picker))); } +fn buffer_picker(cx: &mut Context) { + buffer_picker_impl(cx, false) +} + +fn modified_buffer_picker(cx: &mut Context) { + buffer_picker_impl(cx, true) +} + fn jumplist_picker(cx: &mut Context) { struct JumpMeta { id: DocumentId, diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 5a3e8eed4..2d8cfb5cf 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -222,6 +222,7 @@ pub fn default() -> HashMap { "f" => file_picker, "F" => file_picker_in_current_directory, "b" => buffer_picker, + "B" => modified_buffer_picker, "j" => jumplist_picker, "s" => symbol_picker, "S" => workspace_symbol_picker, From 943ed5d7f8715b8081e920e312a0740b0909f610 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:36:05 +0000 Subject: [PATCH 2/2] docs: add information on B modified_buffer_picker --- book/src/keymap.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/keymap.md b/book/src/keymap.md index 71ae5e31f..cc465d157 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -284,6 +284,7 @@ #### Space mode | `f` | Open file picker | `file_picker` | | `F` | Open file picker at current working directory | `file_picker_in_current_directory` | | `b` | Open buffer picker | `buffer_picker` | +| `B` | Open buffer picker for modified buffers only | `modified_buffer_picker` | | `j` | Open jumplist picker | `jumplist_picker` | | `g` | Open changed file picker | `changed_file_picker` | | `G` | Debug (experimental) | N/A |