vim: Fix "seed_search_query_from_cursor" : "selection"
(#26107)
Closes #9311 Closes #14843 Release Notes: - Fixed vim `"seed_search_query_from_cursor" : "selection"`
This commit is contained in:
parent
d9d3b8847b
commit
47f8f891c8
2 changed files with 29 additions and 2 deletions
|
@ -304,6 +304,7 @@ impl Vim {
|
||||||
};
|
};
|
||||||
let count = Vim::take_count(cx).unwrap_or(1);
|
let count = Vim::take_count(cx).unwrap_or(1);
|
||||||
let prior_selections = self.editor_selections(window, cx);
|
let prior_selections = self.editor_selections(window, cx);
|
||||||
|
let cursor_word = self.editor_cursor_word(window, cx);
|
||||||
let vim = cx.entity().clone();
|
let vim = cx.entity().clone();
|
||||||
|
|
||||||
let searched = pane.update(cx, |pane, cx| {
|
let searched = pane.update(cx, |pane, cx| {
|
||||||
|
@ -325,10 +326,14 @@ impl Vim {
|
||||||
if !search_bar.show(window, cx) {
|
if !search_bar.show(window, cx) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let Some(query) = search_bar.query_suggestion(window, cx) else {
|
let Some(query) = search_bar
|
||||||
|
.query_suggestion(window, cx)
|
||||||
|
.or_else(|| cursor_word)
|
||||||
|
else {
|
||||||
drop(search_bar.search("", None, window, cx));
|
drop(search_bar.search("", None, window, cx));
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = regex::escape(&query);
|
let query = regex::escape(&query);
|
||||||
Some(search_bar.search(&query, Some(options), window, cx))
|
Some(search_bar.search(&query, Some(options), window, cx))
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,7 +30,7 @@ use gpui::{
|
||||||
KeyContext, KeystrokeEvent, Render, Subscription, Task, WeakEntity, Window,
|
KeyContext, KeystrokeEvent, Render, Subscription, Task, WeakEntity, Window,
|
||||||
};
|
};
|
||||||
use insert::{NormalBefore, TemporaryNormal};
|
use insert::{NormalBefore, TemporaryNormal};
|
||||||
use language::{CursorShape, Point, Selection, SelectionGoal, TransactionId};
|
use language::{CharKind, CursorShape, Point, Selection, SelectionGoal, TransactionId};
|
||||||
pub use mode_indicator::ModeIndicator;
|
pub use mode_indicator::ModeIndicator;
|
||||||
use motion::Motion;
|
use motion::Motion;
|
||||||
use normal::search::SearchSubmit;
|
use normal::search::SearchSubmit;
|
||||||
|
@ -1199,6 +1199,28 @@ impl Vim {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn editor_cursor_word(
|
||||||
|
&mut self,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> Option<String> {
|
||||||
|
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||||
|
let selection = editor.selections.newest::<usize>(cx);
|
||||||
|
|
||||||
|
let snapshot = &editor.snapshot(window, cx).buffer_snapshot;
|
||||||
|
let (range, kind) = snapshot.surrounding_word(selection.start, true);
|
||||||
|
if kind == Some(CharKind::Word) {
|
||||||
|
let text: String = snapshot.text_for_range(range).collect();
|
||||||
|
if !text.trim().is_empty() {
|
||||||
|
return Some(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
/// When doing an action that modifies the buffer, we start recording so that `.`
|
/// When doing an action that modifies the buffer, we start recording so that `.`
|
||||||
/// will replay the action.
|
/// will replay the action.
|
||||||
pub fn start_recording(&mut self, cx: &mut Context<Self>) {
|
pub fn start_recording(&mut self, cx: &mut Context<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue