restore editor scroll state after applying edits (#168576)

fixes https://github.com/microsoft/vscode/issues/160934
This commit is contained in:
Johannes Rieken 2022-12-09 13:31:05 +01:00 committed by GitHub
parent 059f680e75
commit 5d3452353b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ import { EditOperation, ISingleEditOperation } from 'vs/editor/common/core/editO
import { Range } from 'vs/editor/common/core/range';
import { EndOfLineSequence } from 'vs/editor/common/model';
import { TextEdit } from 'vs/editor/common/languages';
import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll';
export class FormattingEdit {
@ -47,6 +48,7 @@ export class FormattingEdit {
if (addUndoStops) {
editor.pushUndoStop();
}
const scrollState = StableEditorScrollState.capture(editor);
const edits = FormattingEdit._handleEolEdits(editor, _edits);
if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) {
// We use replace semantics and hope that markers stay put...
@ -57,5 +59,6 @@ export class FormattingEdit {
if (addUndoStops) {
editor.pushUndoStop();
}
scrollState.restoreRelativeVerticalPositionOfCursor(editor);
}
}