Introduce editor.multiCursorPaste (fixes #80624)

This commit is contained in:
Alex Dima
2019-09-10 10:38:58 +02:00
parent 3ff6b96ab7
commit ec9acc5ccd
4 changed files with 38 additions and 10 deletions
+18 -1
View File
@@ -258,7 +258,6 @@ export interface IEditorOptions {
* Defaults to '.'.
*/
wordWrapBreakObtrusiveCharacters?: string;
/**
* Performance guard: Stop rendering a line after x characters.
* Defaults to 10000.
@@ -303,6 +302,11 @@ export interface IEditorOptions {
* Defaults to true
*/
multiCursorMergeOverlapping?: boolean;
/**
* Configure the behaviour when pasting a text with the line count equal to the cursor count.
* Defaults to 'spread'.
*/
multiCursorPaste?: 'spread' | 'full';
/**
* Configure the editor's accessibility support.
* Defaults to 'auto'. It is best to leave this to 'auto'.
@@ -2671,6 +2675,7 @@ export const enum EditorOption {
mouseWheelZoom,
multiCursorMergeOverlapping,
multiCursorModifier,
multiCursorPaste,
occurrencesHighlight,
overviewRulerBorder,
overviewRulerLanes,
@@ -2985,6 +2990,18 @@ export const EditorOptions = {
}, "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).")
}
)),
multiCursorPaste: register(new EditorStringEnumOption(
EditorOption.multiCursorPaste, 'multiCursorPaste',
'spread' as 'spread' | 'full',
['spread', 'full'] as const,
{
markdownEnumDescriptions: [
nls.localize('multiCursorPaste.spread', "Each cursor pastes a single line of the text."),
nls.localize('multiCursorPaste.full', "Each cursor pastes the full text.")
],
markdownDescription: nls.localize('multiCursorPaste', "Controls pasting when the line count of the pasted text matches the cursor count.")
}
)),
occurrencesHighlight: register(new EditorBooleanOption(
EditorOption.occurrencesHighlight, 'occurrencesHighlight', true,
{ description: nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }
@@ -97,6 +97,7 @@ export class CursorConfiguration {
public readonly emptySelectionClipboard: boolean;
public readonly copyWithSyntaxHighlighting: boolean;
public readonly multiCursorMergeOverlapping: boolean;
public readonly multiCursorPaste: 'spread' | 'full';
public readonly autoClosingBrackets: EditorAutoClosingStrategy;
public readonly autoClosingQuotes: EditorAutoClosingStrategy;
public readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy;
@@ -116,6 +117,7 @@ export class CursorConfiguration {
|| e.hasChanged(EditorOption.wordSeparators)
|| e.hasChanged(EditorOption.emptySelectionClipboard)
|| e.hasChanged(EditorOption.multiCursorMergeOverlapping)
|| e.hasChanged(EditorOption.multiCursorPaste)
|| e.hasChanged(EditorOption.autoClosingBrackets)
|| e.hasChanged(EditorOption.autoClosingQuotes)
|| e.hasChanged(EditorOption.autoClosingOvertype)
@@ -147,6 +149,7 @@ export class CursorConfiguration {
this.emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
this.copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
this.multiCursorMergeOverlapping = options.get(EditorOption.multiCursorMergeOverlapping);
this.multiCursorPaste = options.get(EditorOption.multiCursorPaste);
this.autoClosingBrackets = options.get(EditorOption.autoClosingBrackets);
this.autoClosingQuotes = options.get(EditorOption.autoClosingQuotes);
this.autoClosingOvertype = options.get(EditorOption.autoClosingOvertype);
@@ -105,7 +105,7 @@ export class TypeOperations {
});
}
private static _distributePasteToCursors(selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): string[] | null {
private static _distributePasteToCursors(config: CursorConfiguration, selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): string[] | null {
if (pasteOnNewLine) {
return null;
}
@@ -118,20 +118,23 @@ export class TypeOperations {
return multicursorText;
}
// Remove trailing \n if present
if (text.charCodeAt(text.length - 1) === CharCode.LineFeed) {
text = text.substr(0, text.length - 1);
}
let lines = text.split(/\r\n|\r|\n/);
if (lines.length === selections.length) {
return lines;
if (config.multiCursorPaste === 'spread') {
// Try to spread the pasted text in case the line count matches the cursor count
// Remove trailing \n if present
if (text.charCodeAt(text.length - 1) === CharCode.LineFeed) {
text = text.substr(0, text.length - 1);
}
let lines = text.split(/\r\n|\r|\n/);
if (lines.length === selections.length) {
return lines;
}
}
return null;
}
public static paste(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): EditOperationResult {
const distributedPaste = this._distributePasteToCursors(selections, text, pasteOnNewLine, multicursorText);
const distributedPaste = this._distributePasteToCursors(config, selections, text, pasteOnNewLine, multicursorText);
if (distributedPaste) {
selections = selections.sort(Range.compareRangesUsingStarts);
+5
View File
@@ -2704,6 +2704,11 @@ declare namespace monaco.editor {
* Defaults to true
*/
multiCursorMergeOverlapping?: boolean;
/**
* Configure the behaviour when pasting a text with the line count equal to the cursor count.
* Defaults to 'spread'.
*/
multiCursorPaste?: 'spread' | 'full';
/**
* Configure the editor's accessibility support.
* Defaults to 'auto'. It is best to leave this to 'auto'.