diff options
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/editor.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index 70b5758e..09d66c5a 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -87,7 +87,7 @@ impl Editor { // TODO: inefficient, should feed chunks.iter() to tree_sitter.parse_with(|offset, pos|) let source_code = view.state.doc().to_string(); - let last_line = view.last_line(viewport); + let last_line = view.last_line(); let range = { // calculate viewport byte ranges @@ -219,7 +219,7 @@ impl Editor { } let style: Style = view.theme.get("ui.linenr"); - for (i, line) in (view.first_line..(last_line as u16)).enumerate() { + for (i, line) in (view.first_line..last_line).enumerate() { self.surface .set_stringn(0, i as u16, format!("{:>5}", line + 1), 5, style); // lavender @@ -254,6 +254,7 @@ impl Editor { let mode = match view.state.mode() { Mode::Insert => "INS", Mode::Normal => "NOR", + Mode::Goto => "GOTO", }; self.surface.set_style( Rect::new(0, self.size.1 - 1, self.size.0, 1), @@ -278,13 +279,14 @@ impl Editor { match view.state.mode() { Mode::Insert => write!(stdout, "\x1B[6 q"), Mode::Normal => write!(stdout, "\x1B[2 q"), + Mode::Goto => write!(stdout, "\x1B[2 q"), }; // render the cursor let pos = view.state.selection().cursor(); let pos = view - .screen_coords_at_pos(&view.state.doc().slice(..), pos, area) + .screen_coords_at_pos(&view.state.doc().slice(..), pos) .expect("Cursor is out of bounds."); execute!( @@ -326,6 +328,7 @@ impl Editor { }))) => { break; } + Some(Ok(Event::Key(event))) => { if let Some(view) = &mut self.view { match view.state.mode() { @@ -359,6 +362,19 @@ impl Editor { self.render(); } } + Mode::Goto => { + // TODO: handle modes and sequences (`gg`) + let keys = vec![event]; + if let Some(command) = keymap[&Mode::Goto].get(&keys) { + // TODO: handle count other than 1 + command(view, 1); + + // TODO: simplistic ensure cursor in view for now + view.ensure_cursor_in_view(); + + self.render(); + } + } } } } |