summaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-02 06:44:09 +0000
committerBlaž Hrastnik2021-03-02 06:44:09 +0000
commit8f4ff4c646988c377218c08c851297e68e860c65 (patch)
tree984f5293b6f0f6e293b3c2c75def00b39b008030 /helix-view/src/editor.rs
parent32f9a2d1d6fe4955cffffa71bbdfc5a43a6f0c9c (diff)
editor: We still want to be able to calculate cursor pos.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index c5597a34..c072d76f 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -74,4 +74,16 @@ impl Editor {
pub fn view_mut(&mut self) -> &mut View {
self.tree.get_mut(self.tree.focus)
}
+
+ pub fn cursor_position(&self) -> Option<helix_core::Position> {
+ const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
+ let view = self.view();
+ let cursor = view.doc.selection().cursor();
+ if let Some(mut pos) = view.screen_coords_at_pos(view.doc.text().slice(..), cursor) {
+ pos.col += view.area.x as usize + OFFSET as usize;
+ pos.row += view.area.y as usize;
+ return Some(pos);
+ }
+ None
+ }
}