diff options
author | Jan Hrastnik | 2020-10-07 22:02:32 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-10-16 02:53:31 +0000 |
commit | 0c0c2c71034e264204a2ce6d4fd7a17ddbc2245f (patch) | |
tree | 477321145126d7c2c4be3252e331c6574a5f400d /helix-term/src | |
parent | 16828d322a13be5b6f9adb680742cdc2570fbf17 (diff) |
modified editor.render() to prepare for command mode rendering
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/editor.rs | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index 3ebe5971..81012156 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -1,5 +1,5 @@ use clap::ArgMatches as Args; -use helix_core::{indent::TAB_WIDTH, state::Mode, syntax::HighlightEvent, Range, State}; +use helix_core::{indent::TAB_WIDTH, state::Mode, syntax::HighlightEvent, Position, Range, State}; use helix_view::{commands, keymap, View}; use std::{ @@ -242,6 +242,7 @@ impl Editor { Mode::Insert => "INS", Mode::Normal => "NOR", Mode::Goto => "GOTO", + Mode::Command => ":", }; self.surface.set_style( Rect::new(0, self.size.1 - 1, self.size.0, 1), @@ -251,35 +252,45 @@ impl Editor { let text_color = Style::default().fg(Color::Rgb(219, 191, 239)); // lilac self.surface .set_string(1, self.size.1 - 1, mode, text_color); - if let Some(path) = view.state.path() { - self.surface - .set_string(6, self.size.1 - 1, path.to_string_lossy(), text_color); - } - - self.terminal - .backend_mut() - .draw(self.cache.diff(&self.surface).into_iter()); - // swap the buffer - std::mem::swap(&mut self.surface, &mut self.cache); // set cursor shape 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"), + Mode::Command => write!(stdout, "\x1B[2 q"), }; // render the cursor - let pos = view.state.selection().cursor(); + let mut pos: Position; + if view.state.mode() == Mode::Command { + pos = Position::new(self.size.0 as usize, 2); + } else { + if let Some(path) = view.state.path() { + self.surface.set_string( + 6, + self.size.1 - 1, + path.to_string_lossy(), + text_color, + ); + } - let pos = view - .screen_coords_at_pos(&view.state.doc().slice(..), pos) - .expect("Cursor is out of bounds."); + let cursor = view.state.selection().cursor(); - execute!( - stdout, - cursor::MoveTo(pos.col as u16 + viewport.x, pos.row as u16 + viewport.y,) - ); + pos = view + .screen_coords_at_pos(&view.state.doc().slice(..), cursor) + .expect("Cursor is out of bounds."); + pos.col += viewport.x as usize; + pos.row += viewport.y as usize; + } + + self.terminal + .backend_mut() + .draw(self.cache.diff(&self.surface).into_iter()); + // swap the buffer + std::mem::swap(&mut self.surface, &mut self.cache); + + execute!(stdout, cursor::MoveTo(pos.col as u16, pos.row as u16)); } None => (), } @@ -360,6 +371,16 @@ impl Editor { self.render(); } } + Mode::Command => { + // 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); + + self.render(); + } + } } } } |