aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/completion.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-26 15:40:30 +0000
committerNathan Vegdahl2021-07-26 15:40:30 +0000
commit0883b4fae03343978e61fc377775d7ba93f86b40 (patch)
tree1a3d6fe100b39a2cae88842017e441aa3e96707a /helix-term/src/ui/completion.rs
parentf96b8b769b3c7457935b5c02db870af97036f7b6 (diff)
Collect some common patterns into methods on `Range`.
Diffstat (limited to 'helix-term/src/ui/completion.rs')
-rw-r--r--helix-term/src/ui/completion.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 942a2483..2725d53d 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -86,7 +86,10 @@ impl Completion {
let item = item.unwrap();
// if more text was entered, remove it
- let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
if trigger_offset < cursor {
let remove = Transaction::change(
doc.text(),
@@ -109,7 +112,10 @@ impl Completion {
)
} else {
let text = item.insert_text.as_ref().unwrap_or(&item.label);
- let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
Transaction::change(
doc.text(),
vec![(cursor, cursor, Some(text.as_str().into()))].into_iter(),
@@ -155,7 +161,10 @@ impl Completion {
// TODO: hooks should get processed immediately so maybe do it after select!(), before
// looping?
- let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
if self.trigger_offset <= cursor {
let fragment = doc.text().slice(self.trigger_offset..cursor);
let text = Cow::from(fragment);
@@ -212,7 +221,10 @@ impl Component for Completion {
.language()
.and_then(|scope| scope.strip_prefix("source."))
.unwrap_or("");
- let cursor_pos = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor_pos = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row
- view.first_line) as u16;