Add path completion for multiple cursors (#12550)

This commit is contained in:
TornaxO7 2025-01-23 21:31:12 +01:00 committed by GitHub
parent 8986f8b953
commit fa27ae16a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View file

@ -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 {

View file

@ -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),