aboutsummaryrefslogtreecommitdiff
path: root/helix-view
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-view
parentf96b8b769b3c7457935b5c02db870af97036f7b6 (diff)
Collect some common patterns into methods on `Range`.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs10
-rw-r--r--helix-view/src/view.rs5
2 files changed, 12 insertions, 3 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 1cd0af02..d5a76c11 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -145,7 +145,10 @@ impl Editor {
.entry(view.id)
.or_insert_with(|| Selection::point(0));
// TODO: reuse align_view
- let pos = doc.selection(view.id).cursor(doc.text().slice(..));
+ let pos = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
let line = doc.text().char_to_line(pos);
view.first_line = line.saturating_sub(view.area.height as usize / 2);
@@ -295,7 +298,10 @@ impl Editor {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
let view = view!(self);
let doc = &self.documents[view.doc];
- let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {
pos.col += view.area.x as usize + OFFSET as usize;
pos.row += view.area.y as usize;
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 66214691..e90d0eab 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -84,7 +84,10 @@ impl View {
}
pub fn ensure_cursor_in_view(&mut self, doc: &Document) {
- let cursor = doc.selection(self.id).cursor(doc.text().slice(..));
+ let cursor = doc
+ .selection(self.id)
+ .primary()
+ .cursor(doc.text().slice(..));
let pos = coords_at_pos(doc.text().slice(..), cursor);
let line = pos.row;
let col = pos.col;