Use char level diff for Rewrap action for cursor preservation + not reinserting all text (#20368)
Closes #18896 Release Notes: - Fixed #18896 - `editor::Rewrap` now preserves cursors and only inserts whitespace by using character-level diff instead of line-level diff.
This commit is contained in:
parent
6819108bcb
commit
ab20681818
3 changed files with 42 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{motion::Motion, object::Object, state::Mode, Vim};
|
||||
use collections::HashMap;
|
||||
use editor::{display_map::ToDisplayPoint, scroll::Autoscroll, Bias, Editor};
|
||||
use editor::{display_map::ToDisplayPoint, scroll::Autoscroll, Bias, Editor, IsVimMode};
|
||||
use gpui::actions;
|
||||
use language::SelectionGoal;
|
||||
use ui::ViewContext;
|
||||
|
@ -15,7 +15,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
|
|||
vim.update_editor(cx, |vim, editor, cx| {
|
||||
editor.transact(cx, |editor, cx| {
|
||||
let mut positions = vim.save_selection_starts(editor, cx);
|
||||
editor.rewrap_impl(false, cx);
|
||||
editor.rewrap_impl(IsVimMode::Yes, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
if let Some(anchor) = positions.remove(&selection.id) {
|
||||
|
@ -52,7 +52,7 @@ impl Vim {
|
|||
motion.expand_selection(map, selection, times, false, &text_layout_details);
|
||||
});
|
||||
});
|
||||
editor.rewrap_impl(false, cx);
|
||||
editor.rewrap_impl(IsVimMode::Yes, cx);
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = selection_starts.remove(&selection.id).unwrap();
|
||||
|
@ -82,7 +82,7 @@ impl Vim {
|
|||
object.expand_selection(map, selection, around);
|
||||
});
|
||||
});
|
||||
editor.rewrap_impl(false, cx);
|
||||
editor.rewrap_impl(IsVimMode::Yes, cx);
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let anchor = original_positions.remove(&selection.id).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue