Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/handlers/completion/path.rs')
| -rw-r--r-- | helix-term/src/handlers/completion/path.rs | 16 |
1 files changed, 8 insertions, 8 deletions
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), |