Unnamed repository; edit this file 'description' to name the repository.
Add path completion for multiple cursors (#12550)
TornaxO7 2025-01-24
parent 8986f8b · commit fa27ae1
-rw-r--r--helix-term/src/handlers/completion.rs5
-rw-r--r--helix-term/src/handlers/completion/path.rs16
2 files changed, 11 insertions, 10 deletions
diff --git a/helix-term/src/handlers/completion.rs b/helix-term/src/handlers/completion.rs
index f3223487..3b12bd0a 100644
--- a/helix-term/src/handlers/completion.rs
+++ b/helix-term/src/handlers/completion.rs
@@ -184,7 +184,8 @@ fn request_completion(
}
let text = doc.text();
- let cursor = doc.selection(view.id).primary().cursor(text.slice(..));
+ let selection = doc.selection(view.id);
+ let cursor = selection.primary().cursor(text.slice(..));
if trigger.view != view.id || trigger.doc != doc.id() || cursor < trigger.pos {
return;
}
@@ -265,7 +266,7 @@ fn request_completion(
}
.boxed()
})
- .chain(path_completion(cursor, text.clone(), doc, handle.clone()))
+ .chain(path_completion(selection.clone(), doc, handle.clone()))
.collect();
let future = async move {
diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs
index e92be51c..102de6b0 100644
--- a/helix-term/src/handlers/completion/path.rs
+++ b/helix-term/src/handlers/completion/path.rs
@@ -6,8 +6,7 @@ use std::{
};
use futures_util::{future::BoxFuture, FutureExt as _};
-use helix_core as core;
-use helix_core::Transaction;
+use helix_core::{self as core, Selection, Transaction};
use helix_event::TaskHandle;
use helix_stdx::path::{self, canonicalize, fold_home_dir, get_path_suffix};
use helix_view::Document;
@@ -16,8 +15,7 @@ use url::Url;
use super::item::CompletionItem;
pub(crate) fn path_completion(
- cursor: usize,
- text: core::Rope,
+ selection: Selection,
doc: &Document,
handle: TaskHandle,
) -> Option<BoxFuture<'static, anyhow::Result<Vec<CompletionItem>>>> {
@@ -25,6 +23,8 @@ pub(crate) fn path_completion(
return None;
}
+ let text = doc.text().clone();
+ let cursor = selection.primary().cursor(text.slice(..));
let cur_line = text.char_to_line(cursor);
let start = text.line_to_char(cur_line).max(cursor.saturating_sub(1000));
let line_until_cursor = text.slice(start..cursor);
@@ -93,10 +93,10 @@ pub(crate) fn path_completion(
.map(|f| f.len())
.unwrap_or_default();
- let transaction = Transaction::change(
- &text,
- std::iter::once((cursor - edit_diff, cursor, Some((&file_name).into()))),
- );
+ let transaction = Transaction::change_by_selection(&text, &selection, |range| {
+ let cursor = range.cursor(text.slice(..));
+ (cursor - edit_diff, cursor, Some((&file_name).into()))
+ });
Some(CompletionItem::Other(core::CompletionItem {
kind: Cow::Borrowed(kind),