Skip to content

Commit ec9acc5

Browse files
committed
Introduce editor.multiCursorPaste (fixes microsoft#80624)
1 parent 3ff6b96 commit ec9acc5

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

src/vs/editor/common/config/editorOptions.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ export interface IEditorOptions {
258258
* Defaults to '.'.
259259
*/
260260
wordWrapBreakObtrusiveCharacters?: string;
261-
262261
/**
263262
* Performance guard: Stop rendering a line after x characters.
264263
* Defaults to 10000.
@@ -303,6 +302,11 @@ export interface IEditorOptions {
303302
* Defaults to true
304303
*/
305304
multiCursorMergeOverlapping?: boolean;
305+
/**
306+
* Configure the behaviour when pasting a text with the line count equal to the cursor count.
307+
* Defaults to 'spread'.
308+
*/
309+
multiCursorPaste?: 'spread' | 'full';
306310
/**
307311
* Configure the editor's accessibility support.
308312
* Defaults to 'auto'. It is best to leave this to 'auto'.
@@ -2671,6 +2675,7 @@ export const enum EditorOption {
26712675
mouseWheelZoom,
26722676
multiCursorMergeOverlapping,
26732677
multiCursorModifier,
2678+
multiCursorPaste,
26742679
occurrencesHighlight,
26752680
overviewRulerBorder,
26762681
overviewRulerLanes,
@@ -2985,6 +2990,18 @@ export const EditorOptions = {
29852990
}, "The modifier to be used to add multiple cursors with the mouse. The Go To Definition and Open Link mouse gestures will adapt such that they do not conflict with the multicursor modifier. [Read more](https://code.visualstudio.com/docs/editor/codebasics#_multicursor-modifier).")
29862991
}
29872992
)),
2993+
multiCursorPaste: register(new EditorStringEnumOption(
2994+
EditorOption.multiCursorPaste, 'multiCursorPaste',
2995+
'spread' as 'spread' | 'full',
2996+
['spread', 'full'] as const,
2997+
{
2998+
markdownEnumDescriptions: [
2999+
nls.localize('multiCursorPaste.spread', "Each cursor pastes a single line of the text."),
3000+
nls.localize('multiCursorPaste.full', "Each cursor pastes the full text.")
3001+
],
3002+
markdownDescription: nls.localize('multiCursorPaste', "Controls pasting when the line count of the pasted text matches the cursor count.")
3003+
}
3004+
)),
29883005
occurrencesHighlight: register(new EditorBooleanOption(
29893006
EditorOption.occurrencesHighlight, 'occurrencesHighlight', true,
29903007
{ description: nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class CursorConfiguration {
9797
public readonly emptySelectionClipboard: boolean;
9898
public readonly copyWithSyntaxHighlighting: boolean;
9999
public readonly multiCursorMergeOverlapping: boolean;
100+
public readonly multiCursorPaste: 'spread' | 'full';
100101
public readonly autoClosingBrackets: EditorAutoClosingStrategy;
101102
public readonly autoClosingQuotes: EditorAutoClosingStrategy;
102103
public readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy;
@@ -116,6 +117,7 @@ export class CursorConfiguration {
116117
|| e.hasChanged(EditorOption.wordSeparators)
117118
|| e.hasChanged(EditorOption.emptySelectionClipboard)
118119
|| e.hasChanged(EditorOption.multiCursorMergeOverlapping)
120+
|| e.hasChanged(EditorOption.multiCursorPaste)
119121
|| e.hasChanged(EditorOption.autoClosingBrackets)
120122
|| e.hasChanged(EditorOption.autoClosingQuotes)
121123
|| e.hasChanged(EditorOption.autoClosingOvertype)
@@ -147,6 +149,7 @@ export class CursorConfiguration {
147149
this.emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
148150
this.copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
149151
this.multiCursorMergeOverlapping = options.get(EditorOption.multiCursorMergeOverlapping);
152+
this.multiCursorPaste = options.get(EditorOption.multiCursorPaste);
150153
this.autoClosingBrackets = options.get(EditorOption.autoClosingBrackets);
151154
this.autoClosingQuotes = options.get(EditorOption.autoClosingQuotes);
152155
this.autoClosingOvertype = options.get(EditorOption.autoClosingOvertype);

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class TypeOperations {
105105
});
106106
}
107107

108-
private static _distributePasteToCursors(selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): string[] | null {
108+
private static _distributePasteToCursors(config: CursorConfiguration, selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): string[] | null {
109109
if (pasteOnNewLine) {
110110
return null;
111111
}
@@ -118,20 +118,23 @@ export class TypeOperations {
118118
return multicursorText;
119119
}
120120

121-
// Remove trailing \n if present
122-
if (text.charCodeAt(text.length - 1) === CharCode.LineFeed) {
123-
text = text.substr(0, text.length - 1);
124-
}
125-
let lines = text.split(/\r\n|\r|\n/);
126-
if (lines.length === selections.length) {
127-
return lines;
121+
if (config.multiCursorPaste === 'spread') {
122+
// Try to spread the pasted text in case the line count matches the cursor count
123+
// Remove trailing \n if present
124+
if (text.charCodeAt(text.length - 1) === CharCode.LineFeed) {
125+
text = text.substr(0, text.length - 1);
126+
}
127+
let lines = text.split(/\r\n|\r|\n/);
128+
if (lines.length === selections.length) {
129+
return lines;
130+
}
128131
}
129132

130133
return null;
131134
}
132135

133136
public static paste(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): EditOperationResult {
134-
const distributedPaste = this._distributePasteToCursors(selections, text, pasteOnNewLine, multicursorText);
137+
const distributedPaste = this._distributePasteToCursors(config, selections, text, pasteOnNewLine, multicursorText);
135138

136139
if (distributedPaste) {
137140
selections = selections.sort(Range.compareRangesUsingStarts);

src/vs/monaco.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,11 @@ declare namespace monaco.editor {
27042704
* Defaults to true
27052705
*/
27062706
multiCursorMergeOverlapping?: boolean;
2707+
/**
2708+
* Configure the behaviour when pasting a text with the line count equal to the cursor count.
2709+
* Defaults to 'spread'.
2710+
*/
2711+
multiCursorPaste?: 'spread' | 'full';
27072712
/**
27082713
* Configure the editor's accessibility support.
27092714
* Defaults to 'auto'. It is best to leave this to 'auto'.

0 commit comments

Comments
 (0)