Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim: Support ranges in command #15985

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"bindings": {
"i": ["vim::PushOperator", { "Object": { "around": false } }],
"a": ["vim::PushOperator", { "Object": { "around": true } }],
":": "command_palette::Toggle",
"h": "vim::Left",
"left": "vim::Left",
"backspace": "vim::Backspace",
Expand Down Expand Up @@ -199,17 +198,12 @@
"ctrl-6": "pane::AlternateFile"
}
},
{
"context": "VimControl && VimCount",
"bindings": {
"0": ["vim::Number", 0]
}
},
{
"context": "vim_mode == normal",
"bindings": {
"escape": "editor::Cancel",
"ctrl-[": "editor::Cancel",
":": "command_palette::Toggle",
".": "vim::Repeat",
"c": ["vim::PushOperator", "Change"],
"shift-c": "vim::ChangeToEndOfLine",
Expand Down Expand Up @@ -257,9 +251,17 @@
"g c": ["vim::PushOperator", "ToggleComments"]
}
},
{
"context": "VimControl && VimCount",
"bindings": {
"0": ["vim::Number", 0],
":": "vim::CountCommand"
}
},
{
"context": "vim_mode == visual",
"bindings": {
":": "vim::VisualCommand",
"u": "vim::ConvertToLowerCase",
"U": "vim::ConvertToUpperCase",
"o": "vim::OtherEnd",
Expand Down
30 changes: 21 additions & 9 deletions crates/command_palette/src/command_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ fn trim_consecutive_whitespaces(input: &str) -> String {

impl CommandPalette {
fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
workspace.register_action(|workspace, _: &Toggle, cx| {
let Some(previous_focus_handle) = cx.focused() else {
return;
};
let telemetry = workspace.client().telemetry().clone();
workspace.toggle_modal(cx, move |cx| {
CommandPalette::new(previous_focus_handle, telemetry, cx)
});
workspace.register_action(|workspace, _: &Toggle, cx| Self::toggle(workspace, "", cx));
}

pub fn toggle(workspace: &mut Workspace, query: &str, cx: &mut ViewContext<Workspace>) {
let Some(previous_focus_handle) = cx.focused() else {
return;
};
let telemetry = workspace.client().telemetry().clone();
workspace.toggle_modal(cx, move |cx| {
CommandPalette::new(previous_focus_handle, telemetry, query, cx)
});
}

fn new(
previous_focus_handle: FocusHandle,
telemetry: Arc<Telemetry>,
query: &str,
cx: &mut ViewContext<Self>,
) -> Self {
let filter = CommandPaletteFilter::try_global(cx);
Expand All @@ -98,9 +101,18 @@ impl CommandPalette {
previous_focus_handle,
);

let picker = cx.new_view(|cx| Picker::uniform_list(delegate, cx));
let picker = cx.new_view(|cx| {
let picker = Picker::uniform_list(delegate, cx);
picker.set_query(query, cx);
picker
});
Self { picker }
}

pub fn set_query(&mut self, query: &str, cx: &mut ViewContext<Self>) {
self.picker
.update(cx, |picker, cx| picker.set_query(query, cx))
}
}

impl EventEmitter<DismissEvent> for CommandPalette {}
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/selections_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl<'a> MutableSelectionsCollection<'a> {
self.collection.display_map(self.cx)
}

fn buffer(&self) -> Ref<MultiBufferSnapshot> {
pub fn buffer(&self) -> Ref<MultiBufferSnapshot> {
self.collection.buffer(self.cx)
}

Expand Down
1 change: 1 addition & 0 deletions crates/vim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ anyhow.workspace = true
async-compat = { version = "0.2.1", "optional" = true }
async-trait = { workspace = true, "optional" = true }
collections.workspace = true
command_palette.workspace = true
command_palette_hooks.workspace = true
editor.workspace = true
gpui.workspace = true
Expand Down
Loading
Loading