@@ -1,5 +1,5 @@
11use clap::ArgMatches as Args;
2−use helix_core::{indent::TAB_WIDTH, state::Mode, syntax::HighlightEvent, Range, State};
2+use helix_core::{indent::TAB_WIDTH, state::Mode, syntax::HighlightEvent, Position, Range, State};
33use helix_view::{commands, keymap, View};
44
55use std::{
@@ -242,6 +242,7 @@ impl Editor {
242242 Mode::Insert => "INS",
243243 Mode::Normal => "NOR",
244244 Mode::Goto => "GOTO",
245+ Mode::Command => ":",
245246 };
246247 self.surface.set_style(
247248 Rect::new(0, self.size.1 - 1, self.size.0, 1),
@@ -251,35 +252,45 @@ impl Editor {
251252 let text_color = Style::default().fg(Color::Rgb(219, 191, 239)); // lilac
252253 self.surface
253254 .set_string(1, self.size.1 - 1, mode, text_color);
254− if let Some(path) = view.state.path() {
255− self.surface
256− .set_string(6, self.size.1 - 1, path.to_string_lossy(), text_color);
257− }
258−
259− self.terminal
260− .backend_mut()
261− .draw(self.cache.diff(&self.surface).into_iter());
262− // swap the buffer
263− std::mem::swap(&mut self.surface, &mut self.cache);
264255
265256 // set cursor shape
266257 match view.state.mode() {
267258 Mode::Insert => write!(stdout, "\x1B[6 q"),
268259 Mode::Normal => write!(stdout, "\x1B[2 q"),
269260 Mode::Goto => write!(stdout, "\x1B[2 q"),
261+ Mode::Command => write!(stdout, "\x1B[2 q"),
270262 };
271263
272264 // render the cursor
273− let pos = view.state.selection().cursor();
265+ let mut pos: Position;
266+ if view.state.mode() == Mode::Command {
267+ pos = Position::new(self.size.0 as usize, 2);
268+ } else {
269+ if let Some(path) = view.state.path() {
270+ self.surface.set_string(
271+ 6,
272+ self.size.1 - 1,
273+ path.to_string_lossy(),
274+ text_color,
275+ );
276+ }
274277
275− let pos = view
276− .screen_coords_at_pos(&view.state.doc().slice(..), pos)
277− .expect("Cursor is out of bounds.");
278+ let cursor = view.state.selection().cursor();
278279
279− execute!(
280− stdout,
281− cursor::MoveTo(pos.col as u16 + viewport.x, pos.row as u16 + viewport.y,)
282− );
280+ pos = view
281+ .screen_coords_at_pos(&view.state.doc().slice(..), cursor)
282+ .expect("Cursor is out of bounds.");
283+ pos.col += viewport.x as usize;
284+ pos.row += viewport.y as usize;
285+ }
286+
287+ self.terminal
288+ .backend_mut()
289+ .draw(self.cache.diff(&self.surface).into_iter());
290+ // swap the buffer
291+ std::mem::swap(&mut self.surface, &mut self.cache);
292+
293+ execute!(stdout, cursor::MoveTo(pos.col as u16, pos.row as u16));
283294 }
284295 None => (),
285296 }
@@ -357,6 +368,16 @@ impl Editor {
357368 // TODO: simplistic ensure cursor in view for now
358369 view.ensure_cursor_in_view();
359370
371+ self.render();
372+ }
373+ }
374+ Mode::Command => {
375+ // TODO: handle modes and sequences (`gg`)
376+ let keys = vec![event];
377+ if let Some(command) = keymap[&Mode::Goto].get(&keys) {
378+ // TODO: handle count other than 1
379+ command(view, 1);
380+
360381 self.render();
361382 }
362383 }