refactor: name configurable viewport scroll steps accurately
This commit is contained in:
+24
-24
@@ -644,13 +644,13 @@ core_actions![
|
||||
&[Mode::Normal, Mode::Visual]
|
||||
),
|
||||
(
|
||||
"core.scroll_half_up",
|
||||
Action::ScrollHalfUp,
|
||||
"core.scroll_step_up",
|
||||
Action::ScrollStepUp,
|
||||
&[Mode::Normal, Mode::Visual]
|
||||
),
|
||||
(
|
||||
"core.scroll_half_down",
|
||||
Action::ScrollHalfDown,
|
||||
"core.scroll_step_down",
|
||||
Action::ScrollStepDown,
|
||||
&[Mode::Normal, Mode::Visual]
|
||||
),
|
||||
(
|
||||
@@ -1342,8 +1342,8 @@ fn default_bindings() -> HashMap<Mode, HashMap<Input, Binding>> {
|
||||
for (key, action) in [
|
||||
(Input::Ctrl('k'), CloneAbove),
|
||||
(Input::Ctrl('e'), CloneBelow),
|
||||
(Input::Ctrl('u'), ScrollHalfUp),
|
||||
(Input::Ctrl('d'), ScrollHalfDown),
|
||||
(Input::Ctrl('u'), ScrollStepUp),
|
||||
(Input::Ctrl('d'), ScrollStepDown),
|
||||
(Input::Escape, Normal),
|
||||
] {
|
||||
bindings
|
||||
@@ -2009,7 +2009,7 @@ pub struct Editor {
|
||||
popup: PopupConfig,
|
||||
labels: BTreeMap<String, String>,
|
||||
scroll_distance: Option<usize>,
|
||||
scroll_half_page_lines: Option<NonZeroUsize>,
|
||||
scroll_step_lines: Option<NonZeroUsize>,
|
||||
highlight_trailing_whitespace: bool,
|
||||
whitespace_characters: BTreeMap<char, char>,
|
||||
whitespace_scope: WhitespaceScope,
|
||||
@@ -2120,7 +2120,7 @@ impl Editor {
|
||||
popup: PopupConfig::default(),
|
||||
labels: BTreeMap::new(),
|
||||
scroll_distance: Some(0),
|
||||
scroll_half_page_lines: None,
|
||||
scroll_step_lines: None,
|
||||
highlight_trailing_whitespace: false,
|
||||
whitespace_characters: BTreeMap::new(),
|
||||
whitespace_scope: WhitespaceScope::All,
|
||||
@@ -4118,8 +4118,8 @@ impl Editor {
|
||||
self.scroll_distance = distance;
|
||||
}
|
||||
|
||||
pub(crate) fn set_scroll_half_page_lines(&mut self, lines: Option<NonZeroUsize>) {
|
||||
self.scroll_half_page_lines = lines;
|
||||
pub(crate) fn set_scroll_step_lines(&mut self, lines: Option<NonZeroUsize>) {
|
||||
self.scroll_step_lines = lines;
|
||||
}
|
||||
|
||||
pub(crate) fn highlight_trailing_whitespace(&self) -> bool {
|
||||
@@ -4465,8 +4465,8 @@ impl Editor {
|
||||
| Action::Up
|
||||
| Action::ScrollUp
|
||||
| Action::ScrollDown
|
||||
| Action::ScrollHalfUp
|
||||
| Action::ScrollHalfDown
|
||||
| Action::ScrollStepUp
|
||||
| Action::ScrollStepDown
|
||||
| Action::LineStart
|
||||
| Action::LineEnd
|
||||
| Action::DocumentStart
|
||||
@@ -4487,8 +4487,8 @@ impl Editor {
|
||||
Binding::Action(
|
||||
action @ (Action::ScrollUp
|
||||
| Action::ScrollDown
|
||||
| Action::ScrollHalfUp
|
||||
| Action::ScrollHalfDown),
|
||||
| Action::ScrollStepUp
|
||||
| Action::ScrollStepDown),
|
||||
) => Some(action.entry().name),
|
||||
_ => None,
|
||||
}
|
||||
@@ -5834,12 +5834,12 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub(crate) fn take_viewport_scroll(&self, height: usize) -> isize {
|
||||
let (rows, halves) = self.active.view.viewport_scroll.take();
|
||||
let (rows, steps) = self.active.view.viewport_scroll.take();
|
||||
let lines = self
|
||||
.scroll_half_page_lines
|
||||
.scroll_step_lines
|
||||
.map_or((height / 2).max(1), NonZeroUsize::get);
|
||||
let lines = isize::try_from(lines).unwrap_or(isize::MAX);
|
||||
rows.saturating_add(halves.saturating_mul(lines))
|
||||
rows.saturating_add(steps.saturating_mul(lines))
|
||||
}
|
||||
|
||||
fn reveal_caret(&mut self) {
|
||||
@@ -8305,22 +8305,22 @@ impl Editor {
|
||||
Action::JumpForward => self.traverse_jumps(true, count),
|
||||
Action::ScrollUp
|
||||
| Action::ScrollDown
|
||||
| Action::ScrollHalfUp
|
||||
| Action::ScrollHalfDown => {
|
||||
| Action::ScrollStepUp
|
||||
| Action::ScrollStepDown => {
|
||||
if self.document_actions_available() {
|
||||
let amount = isize::try_from(count).unwrap_or(isize::MAX);
|
||||
let amount = if matches!(action, Action::ScrollUp | Action::ScrollHalfUp) {
|
||||
let amount = if matches!(action, Action::ScrollUp | Action::ScrollStepUp) {
|
||||
-amount
|
||||
} else {
|
||||
amount
|
||||
};
|
||||
let (mut rows, mut halves) = self.active.view.viewport_scroll.get();
|
||||
if matches!(action, Action::ScrollHalfUp | Action::ScrollHalfDown) {
|
||||
halves = halves.saturating_add(amount);
|
||||
let (mut rows, mut steps) = self.active.view.viewport_scroll.get();
|
||||
if matches!(action, Action::ScrollStepUp | Action::ScrollStepDown) {
|
||||
steps = steps.saturating_add(amount);
|
||||
} else {
|
||||
rows = rows.saturating_add(amount);
|
||||
}
|
||||
self.active.view.viewport_scroll.set((rows, halves));
|
||||
self.active.view.viewport_scroll.set((rows, steps));
|
||||
if let Some(diff) = self.interaction_diff_mut() {
|
||||
diff.follow_caret = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user