@@ -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+}