Skip to content

Commit 7cfc194

Browse files
committed
1 parent 5bfd23c commit 7cfc194

10 files changed

Lines changed: 206 additions & 166 deletions

File tree

src/vs/editor/common/commands/replaceCommand.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,19 @@ export class ReplaceCommandThatPreservesSelection implements ICommand {
122122
private readonly _range: Range;
123123
private readonly _text: string;
124124
private readonly _initialSelection: Selection;
125+
private readonly _forceMoveMarkers: boolean;
125126
private _selectionId: string | null;
126127

127-
constructor(editRange: Range, text: string, initialSelection: Selection) {
128+
constructor(editRange: Range, text: string, initialSelection: Selection, forceMoveMarkers: boolean = false) {
128129
this._range = editRange;
129130
this._text = text;
130131
this._initialSelection = initialSelection;
132+
this._forceMoveMarkers = forceMoveMarkers;
131133
this._selectionId = null;
132134
}
133135

134136
public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
135-
builder.addEditOperation(this._range, this._text);
137+
builder.addTrackedEditOperation(this._range, this._text, this._forceMoveMarkers);
136138
this._selectionId = builder.trackSelection(this._initialSelection);
137139
}
138140

src/vs/editor/common/controller/cursor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
727727

728728
case H.Paste:
729729
cursorChangeReason = CursorChangeReason.Paste;
730-
this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine, <string[]>payload.multicursorText);
730+
this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine, <string[]>payload.multicursorText || []);
731731
break;
732732

733733
case H.Cut:
@@ -1000,7 +1000,7 @@ class CommandExecutor {
10001000
let operations: IIdentifiedSingleEditOperation[] = [];
10011001
let operationMinor = 0;
10021002

1003-
const addEditOperation = (selection: Range, text: string | null) => {
1003+
const addEditOperation = (selection: Range, text: string | null, forceMoveMarkers: boolean = false) => {
10041004
if (selection.isEmpty() && text === '') {
10051005
// This command wants to add a no-op => no thank you
10061006
return;
@@ -1012,15 +1012,15 @@ class CommandExecutor {
10121012
},
10131013
range: selection,
10141014
text: text,
1015-
forceMoveMarkers: false,
1015+
forceMoveMarkers: forceMoveMarkers,
10161016
isAutoWhitespaceEdit: command.insertsAutoWhitespace
10171017
});
10181018
};
10191019

10201020
let hadTrackedEditOperation = false;
1021-
const addTrackedEditOperation = (selection: Range, text: string | null) => {
1021+
const addTrackedEditOperation = (selection: Range, text: string | null, forceMoveMarkers?: boolean) => {
10221022
hadTrackedEditOperation = true;
1023-
addEditOperation(selection, text);
1023+
addEditOperation(selection, text, forceMoveMarkers);
10241024
};
10251025

10261026
const trackSelection = (selection: Selection, trackPreviousOnEmpty?: boolean) => {

src/vs/editor/common/controller/cursorTypeOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TypeOperations {
9494
if (pasteOnNewLine) {
9595
// Paste entire line at the beginning of line
9696
let typeSelection = new Range(position.lineNumber, 1, position.lineNumber, 1);
97-
commands[i] = new ReplaceCommandThatPreservesSelection(typeSelection, text, selection);
97+
commands[i] = new ReplaceCommandThatPreservesSelection(typeSelection, text, selection, true);
9898
} else {
9999
commands[i] = new ReplaceCommand(selection, text);
100100
}

src/vs/editor/common/editorCommon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export interface IEditOperationBuilder {
2222
* @param range The range to replace (delete). May be empty to represent a simple insert.
2323
* @param text The text to replace with. May be null to represent a simple delete.
2424
*/
25-
addEditOperation(range: Range, text: string | null): void;
25+
addEditOperation(range: Range, text: string | null, forceMoveMarkers?: boolean): void;
2626

2727
/**
2828
* Add a new edit operation (a replace operation).
2929
* The inverse edits will be accessible in `ICursorStateComputerData.getInverseEditOperations()`
3030
* @param range The range to replace (delete). May be empty to represent a simple insert.
3131
* @param text The text to replace with. May be null to represent a simple delete.
3232
*/
33-
addTrackedEditOperation(range: Range, text: string | null): void;
33+
addTrackedEditOperation(range: Range, text: string | null, forceMoveMarkers?: boolean): void;
3434

3535
/**
3636
* Track `selection` when applying edit operations.

0 commit comments

Comments
 (0)