summaryrefslogtreecommitdiff
path: root/helix-term/src/editor.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-07 05:06:25 +0000
committerGitHub2020-10-07 05:06:25 +0000
commit6848702b1f09dc1a4e8d2e3067d3b45b3421d403 (patch)
tree18cc823d2a5dfd0b09b5802f6eb11c978080df36 /helix-term/src/editor.rs
parentb7e1c0cf8253703a5eeb8453de23c8d0a6137ef1 (diff)
parent7f07e6676801be72e5a58b5612893c7d16f94a64 (diff)
Merge pull request #3 from helix-editor/goto-implementation
Goto mode implementation
Diffstat (limited to 'helix-term/src/editor.rs')
-rw-r--r--helix-term/src/editor.rs22
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();
+ }
+ }
}
}
}