vim: Support ranges in command (#15985)

The most requested feature here is "search and replace in visual mode",
but as a happy side effect we can now support things like :2,12j to join
those lines, and much much more.



Release Notes:

- vim: Added support for range syntax in command
([#9428](https://github.com/zed-industries/zed/issues/9428)).
- vim: Prefill command with `:'<,'>` from visual mode
([#13535](https://github.com/zed-industries/zed/issues/13535)).
This commit is contained in:
Conrad Irwin 2024-08-08 21:47:27 +01:00 committed by GitHub
parent b7d6b0a096
commit bd59af1df5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 671 additions and 201 deletions

View file

@ -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);
@ -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 {}