on master help sign in
editor: We still want to be able to calculate cursor pos.
commit8f4ff4c646988c377218c08c851297e68e860c65 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 2 Mar 2021, 15:44 (6 years ago) parent32f9a2d
3 files changed+15−12
helix-term/src/commands.rs+2−4 helix-term/src/ui/editor.rs+1−8 helix-view/src/editor.rs+12
helix-term/src/commands.rs+2−4
@@ -1119,8 +1119,7 @@ pub fn completion(cx: &mut Context) {
11191119
11201120 cx.callback = Some(Box::new(
11211121 move |compositor: &mut Compositor, editor: &mut Editor| {
1122− let area = tui::layout::Rect::default(); // TODO: unused remove from cursor_position
1123− if let Some(mut pos) = compositor.cursor_position(area, editor) {
1122+ if let Some(mut pos) = editor.cursor_position() {
11241123 pos.row += 1; // shift down by one row
11251124 menu.set_position(pos);
11261125 };
@@ -1181,8 +1180,7 @@ pub fn hover(cx: &mut Context) {
11811180
11821181 cx.callback = Some(Box::new(
11831182 move |compositor: &mut Compositor, editor: &mut Editor| {
1184− let area = tui::layout::Rect::default(); // TODO: unused remove from cursor_position
1185− if let Some(mut pos) = compositor.cursor_position(area, editor) {
1183+ if let Some(mut pos) = editor.cursor_position() {
11861184 pos.row += 1; // shift down by one row
11871185 popup.set_position(pos);
11881186 };
helix-term/src/ui/editor.rs+1−8
@@ -433,14 +433,7 @@ impl Component for EditorView {
433433 // Mode::Insert => write!(stdout, "\x1B[6 q"),
434434 // mode => write!(stdout, "\x1B[2 q"),
435435 // };
436− // let view = editor.view();
437− // let cursor = view.doc.selection().cursor();
438−
439− // if let Some(mut pos) = view.screen_coords_at_pos(view.doc.text().slice(..), cursor) {
440− // pos.col += view.area.x as usize + area.x as usize + OFFSET as usize;
441− // pos.row += view.area.y as usize + area.y as usize;
442− // return Some(pos);
443− // }
436+ // return editor.cursor_position()
444437
445438 // It's easier to just not render the cursor and use selection rendering instead.
446439 None
helix-view/src/editor.rs+12
@@ -74,4 +74,16 @@ impl Editor {
7474 pub fn view_mut(&mut self) -> &mut View {
7575 self.tree.get_mut(self.tree.focus)
7676 }
77+
78+ pub fn cursor_position(&self) -> Option<helix_core::Position> {
79+ const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
80+ let view = self.view();
81+ let cursor = view.doc.selection().cursor();
82+ if let Some(mut pos) = view.screen_coords_at_pos(view.doc.text().slice(..), cursor) {
83+ pos.col += view.area.x as usize + OFFSET as usize;
84+ pos.row += view.area.y as usize;
85+ return Some(pos);
86+ }
87+ None
88+ }
7789}