aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands/lsp.rs14
-rw-r--r--helix-term/src/ui/mod.rs22
-rw-r--r--helix-term/src/ui/prompt.rs7
3 files changed, 41 insertions, 2 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs
index 630c47e1..a91e3792 100644
--- a/helix-term/src/commands/lsp.rs
+++ b/helix-term/src/commands/lsp.rs
@@ -885,9 +885,21 @@ pub fn hover(cx: &mut Context) {
}
pub fn rename_symbol(cx: &mut Context) {
- ui::prompt(
+ let (view, doc) = current_ref!(cx.editor);
+ let text = doc.text().slice(..);
+ let primary_selection = doc.selection(view.id).primary();
+ let prefill = if primary_selection.len() > 1 {
+ primary_selection
+ } else {
+ use helix_core::textobject::{textobject_word, TextObject};
+ textobject_word(text, primary_selection, TextObject::Inside, 1, false)
+ }
+ .fragment(text)
+ .into();
+ ui::prompt_with_input(
cx,
"rename-to:".into(),
+ prefill,
None,
ui::completers::none,
move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index c7d409e9..88a226e9 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -34,7 +34,27 @@ pub fn prompt(
completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static,
) {
- let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn);
+ show_prompt(
+ cx,
+ Prompt::new(prompt, history_register, completion_fn, callback_fn),
+ );
+}
+
+pub fn prompt_with_input(
+ cx: &mut crate::commands::Context,
+ prompt: std::borrow::Cow<'static, str>,
+ input: String,
+ history_register: Option<char>,
+ completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
+ callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static,
+) {
+ show_prompt(
+ cx,
+ Prompt::new(prompt, history_register, completion_fn, callback_fn).with_line(input),
+ );
+}
+
+fn show_prompt(cx: &mut crate::commands::Context, mut prompt: Prompt) {
// Calculate initial completion
prompt.recalculate_completion(cx.editor);
cx.push_layer(Box::new(prompt));
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index 36ee62c3..6e7df907 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -84,6 +84,13 @@ impl Prompt {
}
}
+ pub fn with_line(mut self, line: String) -> Self {
+ let cursor = line.len();
+ self.line = line;
+ self.cursor = cursor;
+ self
+ }
+
pub fn line(&self) -> &String {
&self.line
}