vim: Add zH/zL/zh/zl
This commit is contained in:
@@ -155,6 +155,7 @@
|
||||
"z +": ["workspace::SendKeystrokes", "shift-l j z t ^"],
|
||||
"z t": "editor::ScrollCursorTop",
|
||||
"z z": "editor::ScrollCursorCenter",
|
||||
"z l": "vim::ScrollLeftHalfWay",
|
||||
"z .": ["workspace::SendKeystrokes", "z z ^"],
|
||||
"z b": "editor::ScrollCursorBottom",
|
||||
"z a": "editor::ToggleFold",
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
inlay_hint_settings,
|
||||
items::BufferSearchHighlights,
|
||||
mouse_context_menu::{self, MenuPosition, MouseContextMenu},
|
||||
scroll::{axis_pair, scroll_amount::ScrollAmount, AxisPair},
|
||||
scroll::{axis_pair, scroll_amount::ScrollAmount, AxisPair, HorizontalLayoutDetails},
|
||||
BlockId, ChunkReplacement, CursorShape, CustomBlockId, DisplayDiffHunk, DisplayPoint,
|
||||
DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, EditDisplayMode, Editor, EditorMode,
|
||||
EditorSettings, EditorSnapshot, EditorStyle, FocusedBlock, GoToHunk, GoToPreviousHunk,
|
||||
@@ -7031,6 +7031,11 @@ impl Element for EditorElement {
|
||||
);
|
||||
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
editor.scroll_manager.latest_horizontal_details = HorizontalLayoutDetails {
|
||||
letter_width: letter_size.width.0,
|
||||
editor_width: editor_width.0,
|
||||
scroll_max: scroll_max.x,
|
||||
};
|
||||
let clamped = editor.scroll_manager.clamp_scroll_left(scroll_max.x);
|
||||
|
||||
let autoscrolled = if autoscroll_horizontally {
|
||||
|
||||
@@ -172,6 +172,13 @@ impl OngoingScroll {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct HorizontalLayoutDetails {
|
||||
pub letter_width: f32,
|
||||
pub editor_width: f32,
|
||||
pub scroll_max: f32,
|
||||
}
|
||||
|
||||
pub struct ScrollManager {
|
||||
pub(crate) vertical_scroll_margin: f32,
|
||||
anchor: ScrollAnchor,
|
||||
@@ -183,6 +190,7 @@ pub struct ScrollManager {
|
||||
dragging_scrollbar: AxisPair<bool>,
|
||||
visible_line_count: Option<f32>,
|
||||
forbid_vertical_scroll: bool,
|
||||
pub(crate) latest_horizontal_details: HorizontalLayoutDetails,
|
||||
}
|
||||
|
||||
impl ScrollManager {
|
||||
@@ -198,6 +206,7 @@ impl ScrollManager {
|
||||
last_autoscroll: None,
|
||||
visible_line_count: None,
|
||||
forbid_vertical_scroll: false,
|
||||
latest_horizontal_details: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,6 +388,15 @@ impl ScrollManager {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn horizontal_scroll(
|
||||
&mut self,
|
||||
f: impl Fn(f32, &HorizontalLayoutDetails) -> f32,
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
self.anchor.offset.x = f(self.anchor.offset.x, &self.latest_horizontal_details);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn clamp_scroll_left(&mut self, max: f32) -> bool {
|
||||
if max < self.anchor.offset.x {
|
||||
self.anchor.offset.x = max;
|
||||
|
||||
@@ -7,10 +7,20 @@ use editor::{
|
||||
use gpui::{actions, Context, Window};
|
||||
use language::Bias;
|
||||
use settings::Settings;
|
||||
use ui::px;
|
||||
|
||||
actions!(
|
||||
vim,
|
||||
[LineUp, LineDown, ScrollUp, ScrollDown, PageUp, PageDown]
|
||||
[
|
||||
LineUp,
|
||||
LineDown,
|
||||
ScrollUp,
|
||||
ScrollDown,
|
||||
PageUp,
|
||||
PageDown,
|
||||
ScrollLeftHalfWay,
|
||||
ScrollRightHalfWay,
|
||||
]
|
||||
);
|
||||
|
||||
pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
||||
@@ -44,6 +54,25 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Vim::action(editor, cx, |vim, _: &ScrollLeftHalfWay, window, cx| {
|
||||
dbg!("here!");
|
||||
vim.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.scroll_manager.horizontal_scroll(
|
||||
|current, details| (current + details.editor_width / 2.).min(details.scroll_max),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
});
|
||||
// Vim::action(editor, cx, |vim, _: &ScrollRightHalfWay, window, cx| {
|
||||
// vim.scroll_horizontal(window, cx, |c| {
|
||||
// if let Some(c) = c {
|
||||
// ScrollAmount::Line(-c)
|
||||
// } else {
|
||||
// ScrollAmount::Page(-0.5)
|
||||
// }
|
||||
// })
|
||||
// });
|
||||
}
|
||||
|
||||
impl Vim {
|
||||
|
||||
Reference in New Issue
Block a user