on master help sign in
editor: We still want to be able to calculate cursor pos.
8f4ff4cBlaž Hrastnik
helix-term/src/commands.rs+2−4
@@ -1119,8 +1119,7 @@ pub fn completion(cx: &mut Context) {
1119
1119
1120 cx.callback = Some(Box::new(
1120 cx.callback = Some(Box::new(
1121 move |compositor: &mut Compositor, editor: &mut Editor| {
1121 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() {
1124 pos.row += 1; // shift down by one row
1123 pos.row += 1; // shift down by one row
1125 menu.set_position(pos);
1124 menu.set_position(pos);
1126 };
1125 };
@@ -1181,8 +1180,7 @@ pub fn hover(cx: &mut Context) {
1181
1180
1182 cx.callback = Some(Box::new(
1181 cx.callback = Some(Box::new(
1183 move |compositor: &mut Compositor, editor: &mut Editor| {
1182 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() {
1186 pos.row += 1; // shift down by one row
1184 pos.row += 1; // shift down by one row
1187 popup.set_position(pos);
1185 popup.set_position(pos);
1188 };
1186 };
helix-term/src/ui/editor.rs+1−8
@@ -433,14 +433,7 @@ impl Component for EditorView {
433 // Mode::Insert => write!(stdout, "\x1B[6 q"),
433 // Mode::Insert => write!(stdout, "\x1B[6 q"),
434 // mode => write!(stdout, "\x1B[2 q"),
434 // mode => write!(stdout, "\x1B[2 q"),
435 // };
435 // };
436− // let view = editor.view();
436+ // return editor.cursor_position()
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− // }
444
437
445 // It's easier to just not render the cursor and use selection rendering instead.
438 // It's easier to just not render the cursor and use selection rendering instead.
446 None
439 None
helix-view/src/editor.rs+12
@@ -74,4 +74,16 @@ impl Editor {
74 pub fn view_mut(&mut self) -> &mut View {
74 pub fn view_mut(&mut self) -> &mut View {
75 self.tree.get_mut(self.tree.focus)
75 self.tree.get_mut(self.tree.focus)
76 }
76 }
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+ }
77}
89}