editor: We still want to be able to calculate cursor pos.

pull/8/head
Blaž Hrastnik 4 years ago
parent 32f9a2d1d6
commit 8f4ff4c646

@ -1119,8 +1119,7 @@ pub fn completion(cx: &mut Context) {
cx.callback = Some(Box::new( cx.callback = Some(Box::new(
move |compositor: &mut Compositor, editor: &mut Editor| { move |compositor: &mut Compositor, editor: &mut Editor| {
let area = tui::layout::Rect::default(); // TODO: unused remove from cursor_position if let Some(mut pos) = editor.cursor_position() {
if let Some(mut pos) = compositor.cursor_position(area, editor) {
pos.row += 1; // shift down by one row pos.row += 1; // shift down by one row
menu.set_position(pos); menu.set_position(pos);
}; };
@ -1181,8 +1180,7 @@ pub fn hover(cx: &mut Context) {
cx.callback = Some(Box::new( cx.callback = Some(Box::new(
move |compositor: &mut Compositor, editor: &mut Editor| { move |compositor: &mut Compositor, editor: &mut Editor| {
let area = tui::layout::Rect::default(); // TODO: unused remove from cursor_position if let Some(mut pos) = editor.cursor_position() {
if let Some(mut pos) = compositor.cursor_position(area, editor) {
pos.row += 1; // shift down by one row pos.row += 1; // shift down by one row
popup.set_position(pos); popup.set_position(pos);
}; };

@ -433,14 +433,7 @@ impl Component for EditorView {
// Mode::Insert => write!(stdout, "\x1B[6 q"), // Mode::Insert => write!(stdout, "\x1B[6 q"),
// mode => write!(stdout, "\x1B[2 q"), // mode => write!(stdout, "\x1B[2 q"),
// }; // };
// let view = editor.view(); // return editor.cursor_position()
// 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 + area.x as usize + OFFSET as usize;
// pos.row += view.area.y as usize + area.y as usize;
// return Some(pos);
// }
// It's easier to just not render the cursor and use selection rendering instead. // It's easier to just not render the cursor and use selection rendering instead.
None None

@ -74,4 +74,16 @@ impl Editor {
pub fn view_mut(&mut self) -> &mut View { pub fn view_mut(&mut self) -> &mut View {
self.tree.get_mut(self.tree.focus) 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
}
} }

Loading…
Cancel
Save