on master help sign in
Implement most of the view mode (z).
commitc64240b6ef20928424f76ee320f0b2d3a69b1132 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 14 Apr 2021, 17:15 (6 years ago) parent5edb374
2 files changed+48
helix-term/src/commands.rs+47 helix-term/src/keymap.rs+1
helix-term/src/commands.rs+47
@@ -1953,3 +1953,50 @@ pub fn space_mode(cx: &mut Context) {
19531953 }
19541954 })
19551955}
1956+
1957+pub fn view_mode(cx: &mut Context) {
1958+ cx.on_next_key(move |cx, event| {
1959+ if let KeyEvent {
1960+ code: KeyCode::Char(ch),
1961+ ..
1962+ } = event
1963+ {
1964+ // if lock, call cx again
1965+ // TODO: temporarily show VIE in the mode list
1966+ match ch {
1967+ // center
1968+ 'z' | 'c'
1969+ // top
1970+ | 't'
1971+ // bottom
1972+ | 'b' => {
1973+ let (view, doc) = cx.current();
1974+ let pos = doc.selection(view.id).cursor();
1975+ // TODO: extract this centering into a function to share with _goto?
1976+ let line = doc.text().char_to_line(pos);
1977+
1978+ let relative = match ch {
1979+ 'z' | 'c' => view.area.height as usize / 2,
1980+ 't' => 0,
1981+ 'b' => view.area.height as usize,
1982+ _ => unreachable!()
1983+ };
1984+ view.first_line = line.saturating_sub(relative);
1985+ }
1986+ 'm' => {
1987+ let (view, doc) = cx.current();
1988+ let pos = doc.selection(view.id).cursor();
1989+ let pos = coords_at_pos(doc.text().slice(..), pos);
1990+
1991+ const OFFSET: usize = 7; // gutters
1992+ view.first_col = pos.col.saturating_sub((view.area.width as usize - OFFSET) / 2);
1993+ },
1994+ 'h' => (),
1995+ 'j' => scroll(cx, 1, Direction::Forward),
1996+ 'k' => scroll(cx, 1, Direction::Backward),
1997+ 'l' => (),
1998+ _ => (),
1999+ }
2000+ }
2001+ })
2002+}
helix-term/src/keymap.rs+1
@@ -263,6 +263,7 @@ pub fn default() -> Keymaps {
263263 // ctrl!('s') => commands::save_selection,
264264
265265 key!(' ') => commands::space_mode,
266+ key!('z') => commands::view_mode,
266267 );
267268 // TODO: decide whether we want normal mode to also be select mode (kakoune-like), or whether
268269 // we keep this separate select mode. More keys can fit into normal mode then, but it's weird