Disable nav history in vim scrolls (#32656)
Reland of #30345 to fix merge conflicts with the new skip-completions option Fixes #29431 Fixes #17592 Release Notes: - vim: Scrolls are no longer added to the jumplist
This commit is contained in:
parent
0fe35f440d
commit
9166e66519
7 changed files with 208 additions and 119 deletions
|
@ -1222,10 +1222,55 @@ impl Default for SelectionHistoryMode {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SelectionEffects {
|
||||
nav_history: bool,
|
||||
completions: bool,
|
||||
scroll: Option<Autoscroll>,
|
||||
}
|
||||
|
||||
impl Default for SelectionEffects {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
nav_history: true,
|
||||
completions: true,
|
||||
scroll: Some(Autoscroll::fit()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SelectionEffects {
|
||||
pub fn scroll(scroll: Autoscroll) -> Self {
|
||||
Self {
|
||||
scroll: Some(scroll),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_scroll() -> Self {
|
||||
Self {
|
||||
scroll: None,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn completions(self, completions: bool) -> Self {
|
||||
Self {
|
||||
completions,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nav_history(self, nav_history: bool) -> Self {
|
||||
Self {
|
||||
nav_history,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DeferredSelectionEffectsState {
|
||||
changed: bool,
|
||||
should_update_completions: bool,
|
||||
autoscroll: Option<Autoscroll>,
|
||||
effects: SelectionEffects,
|
||||
old_cursor_position: Anchor,
|
||||
history_entry: SelectionHistoryEntry,
|
||||
}
|
||||
|
@ -2708,7 +2753,7 @@ impl Editor {
|
|||
&mut self,
|
||||
local: bool,
|
||||
old_cursor_position: &Anchor,
|
||||
should_update_completions: bool,
|
||||
effects: SelectionEffects,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
|
@ -2766,12 +2811,14 @@ impl Editor {
|
|||
let new_cursor_position = newest_selection.head();
|
||||
let selection_start = newest_selection.start;
|
||||
|
||||
self.push_to_nav_history(
|
||||
*old_cursor_position,
|
||||
Some(new_cursor_position.to_point(buffer)),
|
||||
false,
|
||||
cx,
|
||||
);
|
||||
if effects.nav_history {
|
||||
self.push_to_nav_history(
|
||||
*old_cursor_position,
|
||||
Some(new_cursor_position.to_point(buffer)),
|
||||
false,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
if local {
|
||||
if let Some(buffer_id) = new_cursor_position.buffer_id {
|
||||
|
@ -2802,7 +2849,7 @@ impl Editor {
|
|||
let completion_position = completion_menu.map(|menu| menu.initial_position);
|
||||
drop(context_menu);
|
||||
|
||||
if should_update_completions {
|
||||
if effects.completions {
|
||||
if let Some(completion_position) = completion_position {
|
||||
let start_offset = selection_start.to_offset(buffer);
|
||||
let position_matches = start_offset == completion_position.to_offset(buffer);
|
||||
|
@ -3009,43 +3056,23 @@ impl Editor {
|
|||
/// effects of selection change occur at the end of the transaction.
|
||||
pub fn change_selections<R>(
|
||||
&mut self,
|
||||
autoscroll: Option<Autoscroll>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
change: impl FnOnce(&mut MutableSelectionsCollection<'_>) -> R,
|
||||
) -> R {
|
||||
self.change_selections_inner(true, autoscroll, window, cx, change)
|
||||
}
|
||||
|
||||
pub(crate) fn change_selections_without_updating_completions<R>(
|
||||
&mut self,
|
||||
autoscroll: Option<Autoscroll>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
change: impl FnOnce(&mut MutableSelectionsCollection<'_>) -> R,
|
||||
) -> R {
|
||||
self.change_selections_inner(false, autoscroll, window, cx, change)
|
||||
}
|
||||
|
||||
fn change_selections_inner<R>(
|
||||
&mut self,
|
||||
should_update_completions: bool,
|
||||
autoscroll: Option<Autoscroll>,
|
||||
effects: impl Into<SelectionEffects>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
change: impl FnOnce(&mut MutableSelectionsCollection<'_>) -> R,
|
||||
) -> R {
|
||||
let effects = effects.into();
|
||||
if let Some(state) = &mut self.deferred_selection_effects_state {
|
||||
state.autoscroll = autoscroll.or(state.autoscroll);
|
||||
state.should_update_completions = should_update_completions;
|
||||
state.effects.scroll = effects.scroll.or(state.effects.scroll);
|
||||
state.effects.completions = effects.completions;
|
||||
state.effects.nav_history |= effects.nav_history;
|
||||
let (changed, result) = self.selections.change_with(cx, change);
|
||||
state.changed |= changed;
|
||||
return result;
|
||||
}
|
||||
let mut state = DeferredSelectionEffectsState {
|
||||
changed: false,
|
||||
should_update_completions,
|
||||
autoscroll,
|
||||
effects,
|
||||
old_cursor_position: self.selections.newest_anchor().head(),
|
||||
history_entry: SelectionHistoryEntry {
|
||||
selections: self.selections.disjoint_anchors(),
|
||||
|
@ -3095,19 +3122,13 @@ impl Editor {
|
|||
if state.changed {
|
||||
self.selection_history.push(state.history_entry);
|
||||
|
||||
if let Some(autoscroll) = state.autoscroll {
|
||||
if let Some(autoscroll) = state.effects.scroll {
|
||||
self.request_autoscroll(autoscroll, cx);
|
||||
}
|
||||
|
||||
let old_cursor_position = &state.old_cursor_position;
|
||||
|
||||
self.selections_did_change(
|
||||
true,
|
||||
&old_cursor_position,
|
||||
state.should_update_completions,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
self.selections_did_change(true, &old_cursor_position, state.effects, window, cx);
|
||||
|
||||
if self.should_open_signature_help_automatically(&old_cursor_position, cx) {
|
||||
self.show_signature_help(&ShowSignatureHelp, window, cx);
|
||||
|
@ -3227,9 +3248,13 @@ impl Editor {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
let auto_scroll = EditorSettings::get_global(cx).autoscroll_on_clicks;
|
||||
let effects = if EditorSettings::get_global(cx).autoscroll_on_clicks {
|
||||
SelectionEffects::scroll(Autoscroll::fit())
|
||||
} else {
|
||||
SelectionEffects::no_scroll()
|
||||
};
|
||||
|
||||
self.change_selections(auto_scroll.then(Autoscroll::fit), window, cx, |s| {
|
||||
self.change_selections(effects, window, cx, |s| {
|
||||
s.set_pending(pending_selection, pending_mode)
|
||||
});
|
||||
}
|
||||
|
@ -4016,8 +4041,8 @@ impl Editor {
|
|||
}
|
||||
|
||||
let had_active_inline_completion = this.has_active_inline_completion();
|
||||
this.change_selections_without_updating_completions(
|
||||
Some(Autoscroll::fit()),
|
||||
this.change_selections(
|
||||
SelectionEffects::scroll(Autoscroll::fit()).completions(false),
|
||||
window,
|
||||
cx,
|
||||
|s| s.select(new_selections),
|
||||
|
@ -16169,7 +16194,13 @@ impl Editor {
|
|||
s.clear_pending();
|
||||
}
|
||||
});
|
||||
self.selections_did_change(false, &old_cursor_position, true, window, cx);
|
||||
self.selections_did_change(
|
||||
false,
|
||||
&old_cursor_position,
|
||||
SelectionEffects::default(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn transact(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue