mirror of https://github.com/helix-editor/helix
Add infobox for view
parent
bb121a3e4b
commit
3e4cd8f8e6
|
@ -40,6 +40,7 @@ use crate::{
|
||||||
use crate::job::{self, Job, Jobs};
|
use crate::job::{self, Job, Jobs};
|
||||||
use futures_util::{FutureExt, TryFutureExt};
|
use futures_util::{FutureExt, TryFutureExt};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::num::NonZeroUsize;
|
||||||
use std::{fmt, future::Future};
|
use std::{fmt, future::Future};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -52,7 +53,7 @@ use serde::de::{self, Deserialize, Deserializer};
|
||||||
|
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
pub selected_register: helix_view::RegisterSelection,
|
pub selected_register: helix_view::RegisterSelection,
|
||||||
pub count: Option<std::num::NonZeroUsize>,
|
pub count: Option<NonZeroUsize>,
|
||||||
pub editor: &'a mut Editor,
|
pub editor: &'a mut Editor,
|
||||||
|
|
||||||
pub callback: Option<crate::compositor::Callback>,
|
pub callback: Option<crate::compositor::Callback>,
|
||||||
|
@ -3384,47 +3385,38 @@ fn select_register(cx: &mut Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_mode(cx: &mut Context) {
|
fn align_view_top(cx: &mut Context) {
|
||||||
cx.on_next_key(move |cx, event| {
|
let (view, doc) = current!(cx.editor);
|
||||||
if let KeyEvent {
|
align_view(doc, view, Align::Top);
|
||||||
code: KeyCode::Char(ch),
|
}
|
||||||
..
|
|
||||||
} = event
|
|
||||||
{
|
|
||||||
// if lock, call cx again
|
|
||||||
// TODO: temporarily show VIE in the mode list
|
|
||||||
match ch {
|
|
||||||
// center
|
|
||||||
'z' | 'c'
|
|
||||||
// top
|
|
||||||
| 't'
|
|
||||||
// bottom
|
|
||||||
| 'b' => {
|
|
||||||
let (view, doc) = current!(cx.editor);
|
|
||||||
|
|
||||||
align_view(doc, view, match ch {
|
fn align_view_center(cx: &mut Context) {
|
||||||
'z' | 'c' => Align::Center,
|
let (view, doc) = current!(cx.editor);
|
||||||
't' => Align::Top,
|
align_view(doc, view, Align::Center);
|
||||||
'b' => Align::Bottom,
|
}
|
||||||
_ => unreachable!()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
'm' => {
|
|
||||||
let (view, doc) = current!(cx.editor);
|
|
||||||
let pos = doc.selection(view.id).cursor();
|
|
||||||
let pos = coords_at_pos(doc.text().slice(..), pos);
|
|
||||||
|
|
||||||
const OFFSET: usize = 7; // gutters
|
fn align_view_bottom(cx: &mut Context) {
|
||||||
view.first_col = pos.col.saturating_sub(((view.area.width as usize).saturating_sub(OFFSET)) / 2);
|
let (view, doc) = current!(cx.editor);
|
||||||
},
|
align_view(doc, view, Align::Bottom);
|
||||||
'h' => (),
|
}
|
||||||
'j' => scroll(cx, 1, Direction::Forward),
|
|
||||||
'k' => scroll(cx, 1, Direction::Backward),
|
fn align_view_middle(cx: &mut Context) {
|
||||||
'l' => (),
|
let (view, doc) = current!(cx.editor);
|
||||||
_ => (),
|
let pos = doc.selection(view.id).cursor();
|
||||||
}
|
let pos = coords_at_pos(doc.text().slice(..), pos);
|
||||||
}
|
|
||||||
})
|
const OFFSET: usize = 7; // gutters
|
||||||
|
view.first_col = pos
|
||||||
|
.col
|
||||||
|
.saturating_sub(((view.area.width as usize).saturating_sub(OFFSET)) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_up(cx: &mut Context) {
|
||||||
|
scroll(cx, cx.count(), Direction::Backward);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_down(cx: &mut Context) {
|
||||||
|
scroll(cx, cx.count(), Direction::Forward);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_textobject_around(cx: &mut Context) {
|
fn select_textobject_around(cx: &mut Context) {
|
||||||
|
@ -3732,3 +3724,20 @@ mode_info! {
|
||||||
/// diagnostic (last)
|
/// diagnostic (last)
|
||||||
"D" => goto_last_diag,
|
"D" => goto_last_diag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mode_info! {
|
||||||
|
/// view
|
||||||
|
view_mode, VIEW_MODE,
|
||||||
|
/// align view top
|
||||||
|
"t" => align_view_top,
|
||||||
|
/// align view center
|
||||||
|
"z" | "c" => align_view_center,
|
||||||
|
/// align view bottom
|
||||||
|
"b" => align_view_bottom,
|
||||||
|
/// align view middle
|
||||||
|
"m" => align_view_middle,
|
||||||
|
/// scroll up
|
||||||
|
"k" => scroll_up,
|
||||||
|
/// scroll down
|
||||||
|
"j" => scroll_down,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue