@@ -40,6 +40,7 @@ use crate::{
40use crate::job::{self, Job, Jobs};
40use crate::job::{self, Job, Jobs};
41use futures_util::{FutureExt, TryFutureExt};
41use futures_util::{FutureExt, TryFutureExt};
42use std::collections::HashMap;
42use std::collections::HashMap;
43+use std::num::NonZeroUsize;
43use std::{fmt, future::Future};
44use std::{fmt, future::Future};
@@ -52,7 +53,7 @@ use serde::de::{self, Deserialize, Deserializer};
53pub struct Context<'a> {
54pub struct Context<'a> {
54 pub selected_register: helix_view::RegisterSelection,
55 pub selected_register: helix_view::RegisterSelection,
55− pub count: Option<std::num::NonZeroUsize>,
56+ pub count: Option<NonZeroUsize>,
56 pub editor: &'a mut Editor,
57 pub editor: &'a mut Editor,
58 pub callback: Option<crate::compositor::Callback>,
59 pub callback: Option<crate::compositor::Callback>,
@@ -3384,47 +3385,38 @@ fn select_register(cx: &mut Context) {
3387−fn view_mode(cx: &mut Context) {
3388+fn align_view_top(cx: &mut Context) {
3388− cx.on_next_key(move |cx, event| {
3390− code: KeyCode::Char(ch),
3394− // if lock, call cx again
3395− // TODO: temporarily show VIE in the mode list
3403− let (view, doc) = current!(cx.editor);
3389+ let (view, doc) = current!(cx.editor);
3390+ align_view(doc, view, Align::Top);
3405− align_view(doc, view, match ch {
3393+fn align_view_center(cx: &mut Context) {
3406− 'z' | 'c' => Align::Center,
3408− 'b' => Align::Bottom,
3409− _ => unreachable!()
3413− let (view, doc) = current!(cx.editor);
3394+ let (view, doc) = current!(cx.editor);
3414− let pos = doc.selection(view.id).cursor();
3395+ align_view(doc, view, Align::Center);
3415− let pos = coords_at_pos(doc.text().slice(..), pos);
3396+}
3398+fn align_view_bottom(cx: &mut Context) {
3399+ let (view, doc) = current!(cx.editor);
3400+ align_view(doc, view, Align::Bottom);
3403+fn align_view_middle(cx: &mut Context) {
3404+ let (view, doc) = current!(cx.editor);
3405+ let pos = doc.selection(view.id).cursor();
3406+ let pos = coords_at_pos(doc.text().slice(..), pos);
3417− const OFFSET: usize = 7; // gutters
3408+ const OFFSET: usize = 7; // gutters
3409+ view.first_col = pos
3418− view.first_col = pos.col.saturating_sub(((view.area.width as usize).saturating_sub(OFFSET)) / 2);
3411+ .saturating_sub(((view.area.width as usize).saturating_sub(OFFSET)) / 2);
3414+fn scroll_up(cx: &mut Context) {
3415+ scroll(cx, cx.count(), Direction::Backward);
3418+fn scroll_down(cx: &mut Context) {
3421− 'j' => scroll(cx, 1, Direction::Forward),
3419+ scroll(cx, cx.count(), Direction::Forward);
3422− 'k' => scroll(cx, 1, Direction::Backward),
3430fn select_textobject_around(cx: &mut Context) {
3422fn select_textobject_around(cx: &mut Context) {
@@ -3732,3 +3724,20 @@ mode_info! {
3732 /// diagnostic (last)
3724 /// diagnostic (last)
3733 "D" => goto_last_diag,
3725 "D" => goto_last_diag,
3730+ view_mode, VIEW_MODE,
3732+ "t" => align_view_top,
3733+ /// align view center
3734+ "z" | "c" => align_view_center,
3735+ /// align view bottom
3736+ "b" => align_view_bottom,
3737+ /// align view middle
3738+ "m" => align_view_middle,
3742+ "j" => scroll_down,