aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
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
parentf96b8b769b3c7457935b5c02db870af97036f7b6 (diff)
Collect some common patterns into methods on `Range`.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/completion.rs20
-rw-r--r--helix-term/src/ui/editor.rs14
2 files changed, 27 insertions, 7 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;
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 8e29be6c..482a4117 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -406,7 +406,10 @@ impl EditorView {
// TODO: set cursor position for IME
if let Some(syntax) = doc.syntax() {
use helix_core::match_brackets;
- let pos = doc.selection(view.id).cursor(doc.text().slice(..));
+ let pos = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
let pos = match_brackets::find(syntax, doc.text(), pos)
.and_then(|pos| view.screen_coords_at_pos(doc, text, pos));
@@ -451,7 +454,10 @@ impl EditorView {
widgets::{Paragraph, Widget},
};
- let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
let diagnostics = doc.diagnostics().iter().filter(|diagnostic| {
diagnostic.range.start <= cursor && diagnostic.range.end >= cursor
@@ -565,7 +571,9 @@ impl EditorView {
let position_info = {
let pos = coords_at_pos(
doc.text().slice(..),
- doc.selection(view.id).cursor(doc.text().slice(..)),
+ doc.selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..)),
);
format!("{}:{}", pos.row + 1, pos.col + 1) // convert to 1-indexing
};