Skip to content

Commit b954f50

Browse files
committed
feat: add setting for multi cursor limit
1 parent f08feed commit b954f50

File tree

6 files changed

+169
-133
lines changed

6 files changed

+169
-133
lines changed

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
2424
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view';
2525
import { ViewUserInputEvents } from 'vs/editor/browser/view/viewUserInputEvents';
2626
import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, filterValidationDecorations } from 'vs/editor/common/config/editorOptions';
27-
import { CursorsController } from 'vs/editor/common/cursor/cursor';
2827
import { CursorColumns } from 'vs/editor/common/core/cursorColumns';
2928
import { CursorChangeReason, ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/cursorEvents';
3029
import { IPosition, Position } from 'vs/editor/common/core/position';
@@ -46,7 +45,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
4645
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
4746
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
4847
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
49-
import { INotificationService } from 'vs/platform/notification/common/notification';
48+
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
5049
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
5150
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
5251
import { withNullAsUndefined } from 'vs/base/common/types';
@@ -1663,7 +1662,25 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
16631662
break;
16641663
case OutgoingViewModelEventKind.CursorStateChanged: {
16651664
if (e.reachedMaxCursorCount) {
1666-
this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", CursorsController.MAX_CURSOR_COUNT));
1665+
1666+
const multiCursorLimit = this.getOption(EditorOption.multiCursorLimit);
1667+
const message = nls.localize('cursors.maximum', "The number of cursors has been limited to {0}. Consider using [find and replace](https://code.visualstudio.com/docs/editor/codebasics#_find-and-replace) for larger changes.", multiCursorLimit);
1668+
this._notificationService.prompt(Severity.Warning, message, [
1669+
{
1670+
label: 'Find and Replace',
1671+
run: () => {
1672+
this._commandService.executeCommand('editor.action.startFindReplaceAction');
1673+
}
1674+
},
1675+
{
1676+
label: nls.localize('goToSetting', 'Open Settings'),
1677+
run: () => {
1678+
this._commandService.executeCommand('workbench.action.openSettings2', {
1679+
query: 'editor.multiCursorLimit'
1680+
});
1681+
}
1682+
}
1683+
]);
16671684
}
16681685

16691686
const positions: Position[] = [];

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ export interface IEditorOptions {
380380
* Defaults to 'spread'.
381381
*/
382382
multiCursorPaste?: 'spread' | 'full';
383+
/**
384+
* Controls the max number of text cursors that can be in an active editor at once.
385+
*/
386+
multiCursorLimit?: number;
383387
/**
384388
* Configure the editor's accessibility support.
385389
* Defaults to 'auto'. It is best to leave this to 'auto'.
@@ -4729,6 +4733,7 @@ export const enum EditorOption {
47294733
multiCursorMergeOverlapping,
47304734
multiCursorModifier,
47314735
multiCursorPaste,
4736+
multiCursorLimit,
47324737
occurrencesHighlight,
47334738
overviewRulerBorder,
47344739
overviewRulerLanes,
@@ -5150,6 +5155,12 @@ export const EditorOptions = {
51505155
markdownDescription: nls.localize('multiCursorPaste', "Controls pasting when the line count of the pasted text matches the cursor count.")
51515156
}
51525157
)),
5158+
multiCursorLimit: register(new EditorIntOption(
5159+
EditorOption.multiCursorLimit, 'multiCursorLimit', 10000, 1, 100000,
5160+
{
5161+
markdownDescription: nls.localize('multiCursorLimit', "Controls the max number of text cursors that can be in an active editor at once.")
5162+
}
5163+
)),
51535164
occurrencesHighlight: register(new EditorBooleanOption(
51545165
EditorOption.occurrencesHighlight, 'occurrencesHighlight', true,
51555166
{ description: nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import { CursorStateChangedEvent, ViewModelEventsCollector } from 'vs/editor/com
2424

2525
export class CursorsController extends Disposable {
2626

27-
public static readonly MAX_CURSOR_COUNT = 10000;
28-
2927
private readonly _model: ITextModel;
3028
private _knownModelVersionId: number;
3129
private readonly _viewModel: ICursorSimpleModel;
@@ -117,8 +115,9 @@ export class CursorsController extends Disposable {
117115

118116
public setStates(eventsCollector: ViewModelEventsCollector, source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): boolean {
119117
let reachedMaxCursorCount = false;
120-
if (states !== null && states.length > CursorsController.MAX_CURSOR_COUNT) {
121-
states = states.slice(0, CursorsController.MAX_CURSOR_COUNT);
118+
const multiCursorLimit = this.context.cursorConfig.multiCursorLimit;
119+
if (states !== null && states.length > multiCursorLimit) {
120+
states = states.slice(0, multiCursorLimit);
122121
reachedMaxCursorCount = true;
123122
}
124123

src/vs/editor/common/cursorCommon.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class CursorConfiguration {
6464
public readonly copyWithSyntaxHighlighting: boolean;
6565
public readonly multiCursorMergeOverlapping: boolean;
6666
public readonly multiCursorPaste: 'spread' | 'full';
67+
public readonly multiCursorLimit: number;
6768
public readonly autoClosingBrackets: EditorAutoClosingStrategy;
6869
public readonly autoClosingQuotes: EditorAutoClosingStrategy;
6970
public readonly autoClosingDelete: EditorAutoClosingEditStrategy;
@@ -121,6 +122,7 @@ export class CursorConfiguration {
121122
this.copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
122123
this.multiCursorMergeOverlapping = options.get(EditorOption.multiCursorMergeOverlapping);
123124
this.multiCursorPaste = options.get(EditorOption.multiCursorPaste);
125+
this.multiCursorLimit = options.get(EditorOption.multiCursorLimit);
124126
this.autoClosingBrackets = options.get(EditorOption.autoClosingBrackets);
125127
this.autoClosingQuotes = options.get(EditorOption.autoClosingQuotes);
126128
this.autoClosingDelete = options.get(EditorOption.autoClosingDelete);

src/vs/editor/common/standalone/standaloneEnums.ts

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -245,69 +245,70 @@ export enum EditorOption {
245245
multiCursorMergeOverlapping = 70,
246246
multiCursorModifier = 71,
247247
multiCursorPaste = 72,
248-
occurrencesHighlight = 73,
249-
overviewRulerBorder = 74,
250-
overviewRulerLanes = 75,
251-
padding = 76,
252-
parameterHints = 77,
253-
peekWidgetDefaultFocus = 78,
254-
definitionLinkOpensInPeek = 79,
255-
quickSuggestions = 80,
256-
quickSuggestionsDelay = 81,
257-
readOnly = 82,
258-
renameOnType = 83,
259-
renderControlCharacters = 84,
260-
renderFinalNewline = 85,
261-
renderLineHighlight = 86,
262-
renderLineHighlightOnlyWhenFocus = 87,
263-
renderValidationDecorations = 88,
264-
renderWhitespace = 89,
265-
revealHorizontalRightPadding = 90,
266-
roundedSelection = 91,
267-
rulers = 92,
268-
scrollbar = 93,
269-
scrollBeyondLastColumn = 94,
270-
scrollBeyondLastLine = 95,
271-
scrollPredominantAxis = 96,
272-
selectionClipboard = 97,
273-
selectionHighlight = 98,
274-
selectOnLineNumbers = 99,
275-
showFoldingControls = 100,
276-
showUnused = 101,
277-
snippetSuggestions = 102,
278-
smartSelect = 103,
279-
smoothScrolling = 104,
280-
stickyScroll = 105,
281-
stickyTabStops = 106,
282-
stopRenderingLineAfter = 107,
283-
suggest = 108,
284-
suggestFontSize = 109,
285-
suggestLineHeight = 110,
286-
suggestOnTriggerCharacters = 111,
287-
suggestSelection = 112,
288-
tabCompletion = 113,
289-
tabIndex = 114,
290-
unicodeHighlighting = 115,
291-
unusualLineTerminators = 116,
292-
useShadowDOM = 117,
293-
useTabStops = 118,
294-
wordBreak = 119,
295-
wordSeparators = 120,
296-
wordWrap = 121,
297-
wordWrapBreakAfterCharacters = 122,
298-
wordWrapBreakBeforeCharacters = 123,
299-
wordWrapColumn = 124,
300-
wordWrapOverride1 = 125,
301-
wordWrapOverride2 = 126,
302-
wrappingIndent = 127,
303-
wrappingStrategy = 128,
304-
showDeprecated = 129,
305-
inlayHints = 130,
306-
editorClassName = 131,
307-
pixelRatio = 132,
308-
tabFocusMode = 133,
309-
layoutInfo = 134,
310-
wrappingInfo = 135
248+
multiCursorLimit = 73,
249+
occurrencesHighlight = 74,
250+
overviewRulerBorder = 75,
251+
overviewRulerLanes = 76,
252+
padding = 77,
253+
parameterHints = 78,
254+
peekWidgetDefaultFocus = 79,
255+
definitionLinkOpensInPeek = 80,
256+
quickSuggestions = 81,
257+
quickSuggestionsDelay = 82,
258+
readOnly = 83,
259+
renameOnType = 84,
260+
renderControlCharacters = 85,
261+
renderFinalNewline = 86,
262+
renderLineHighlight = 87,
263+
renderLineHighlightOnlyWhenFocus = 88,
264+
renderValidationDecorations = 89,
265+
renderWhitespace = 90,
266+
revealHorizontalRightPadding = 91,
267+
roundedSelection = 92,
268+
rulers = 93,
269+
scrollbar = 94,
270+
scrollBeyondLastColumn = 95,
271+
scrollBeyondLastLine = 96,
272+
scrollPredominantAxis = 97,
273+
selectionClipboard = 98,
274+
selectionHighlight = 99,
275+
selectOnLineNumbers = 100,
276+
showFoldingControls = 101,
277+
showUnused = 102,
278+
snippetSuggestions = 103,
279+
smartSelect = 104,
280+
smoothScrolling = 105,
281+
stickyScroll = 106,
282+
stickyTabStops = 107,
283+
stopRenderingLineAfter = 108,
284+
suggest = 109,
285+
suggestFontSize = 110,
286+
suggestLineHeight = 111,
287+
suggestOnTriggerCharacters = 112,
288+
suggestSelection = 113,
289+
tabCompletion = 114,
290+
tabIndex = 115,
291+
unicodeHighlighting = 116,
292+
unusualLineTerminators = 117,
293+
useShadowDOM = 118,
294+
useTabStops = 119,
295+
wordBreak = 120,
296+
wordSeparators = 121,
297+
wordWrap = 122,
298+
wordWrapBreakAfterCharacters = 123,
299+
wordWrapBreakBeforeCharacters = 124,
300+
wordWrapColumn = 125,
301+
wordWrapOverride1 = 126,
302+
wordWrapOverride2 = 127,
303+
wrappingIndent = 128,
304+
wrappingStrategy = 129,
305+
showDeprecated = 130,
306+
inlayHints = 131,
307+
editorClassName = 132,
308+
pixelRatio = 133,
309+
tabFocusMode = 134,
310+
layoutInfo = 135,
311+
wrappingInfo = 136
311312
}
312313

313314
/**

src/vs/monaco.d.ts

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,10 @@ declare namespace monaco.editor {
33413341
* Defaults to 'spread'.
33423342
*/
33433343
multiCursorPaste?: 'spread' | 'full';
3344+
/**
3345+
* Controls the max number of text cursors that can be in an active editor at once.
3346+
*/
3347+
multiCursorLimit?: number;
33443348
/**
33453349
* Configure the editor's accessibility support.
33463350
* Defaults to 'auto'. It is best to leave this to 'auto'.
@@ -4622,69 +4626,70 @@ declare namespace monaco.editor {
46224626
multiCursorMergeOverlapping = 70,
46234627
multiCursorModifier = 71,
46244628
multiCursorPaste = 72,
4625-
occurrencesHighlight = 73,
4626-
overviewRulerBorder = 74,
4627-
overviewRulerLanes = 75,
4628-
padding = 76,
4629-
parameterHints = 77,
4630-
peekWidgetDefaultFocus = 78,
4631-
definitionLinkOpensInPeek = 79,
4632-
quickSuggestions = 80,
4633-
quickSuggestionsDelay = 81,
4634-
readOnly = 82,
4635-
renameOnType = 83,
4636-
renderControlCharacters = 84,
4637-
renderFinalNewline = 85,
4638-
renderLineHighlight = 86,
4639-
renderLineHighlightOnlyWhenFocus = 87,
4640-
renderValidationDecorations = 88,
4641-
renderWhitespace = 89,
4642-
revealHorizontalRightPadding = 90,
4643-
roundedSelection = 91,
4644-
rulers = 92,
4645-
scrollbar = 93,
4646-
scrollBeyondLastColumn = 94,
4647-
scrollBeyondLastLine = 95,
4648-
scrollPredominantAxis = 96,
4649-
selectionClipboard = 97,
4650-
selectionHighlight = 98,
4651-
selectOnLineNumbers = 99,
4652-
showFoldingControls = 100,
4653-
showUnused = 101,
4654-
snippetSuggestions = 102,
4655-
smartSelect = 103,
4656-
smoothScrolling = 104,
4657-
stickyScroll = 105,
4658-
stickyTabStops = 106,
4659-
stopRenderingLineAfter = 107,
4660-
suggest = 108,
4661-
suggestFontSize = 109,
4662-
suggestLineHeight = 110,
4663-
suggestOnTriggerCharacters = 111,
4664-
suggestSelection = 112,
4665-
tabCompletion = 113,
4666-
tabIndex = 114,
4667-
unicodeHighlighting = 115,
4668-
unusualLineTerminators = 116,
4669-
useShadowDOM = 117,
4670-
useTabStops = 118,
4671-
wordBreak = 119,
4672-
wordSeparators = 120,
4673-
wordWrap = 121,
4674-
wordWrapBreakAfterCharacters = 122,
4675-
wordWrapBreakBeforeCharacters = 123,
4676-
wordWrapColumn = 124,
4677-
wordWrapOverride1 = 125,
4678-
wordWrapOverride2 = 126,
4679-
wrappingIndent = 127,
4680-
wrappingStrategy = 128,
4681-
showDeprecated = 129,
4682-
inlayHints = 130,
4683-
editorClassName = 131,
4684-
pixelRatio = 132,
4685-
tabFocusMode = 133,
4686-
layoutInfo = 134,
4687-
wrappingInfo = 135
4629+
multiCursorLimit = 73,
4630+
occurrencesHighlight = 74,
4631+
overviewRulerBorder = 75,
4632+
overviewRulerLanes = 76,
4633+
padding = 77,
4634+
parameterHints = 78,
4635+
peekWidgetDefaultFocus = 79,
4636+
definitionLinkOpensInPeek = 80,
4637+
quickSuggestions = 81,
4638+
quickSuggestionsDelay = 82,
4639+
readOnly = 83,
4640+
renameOnType = 84,
4641+
renderControlCharacters = 85,
4642+
renderFinalNewline = 86,
4643+
renderLineHighlight = 87,
4644+
renderLineHighlightOnlyWhenFocus = 88,
4645+
renderValidationDecorations = 89,
4646+
renderWhitespace = 90,
4647+
revealHorizontalRightPadding = 91,
4648+
roundedSelection = 92,
4649+
rulers = 93,
4650+
scrollbar = 94,
4651+
scrollBeyondLastColumn = 95,
4652+
scrollBeyondLastLine = 96,
4653+
scrollPredominantAxis = 97,
4654+
selectionClipboard = 98,
4655+
selectionHighlight = 99,
4656+
selectOnLineNumbers = 100,
4657+
showFoldingControls = 101,
4658+
showUnused = 102,
4659+
snippetSuggestions = 103,
4660+
smartSelect = 104,
4661+
smoothScrolling = 105,
4662+
stickyScroll = 106,
4663+
stickyTabStops = 107,
4664+
stopRenderingLineAfter = 108,
4665+
suggest = 109,
4666+
suggestFontSize = 110,
4667+
suggestLineHeight = 111,
4668+
suggestOnTriggerCharacters = 112,
4669+
suggestSelection = 113,
4670+
tabCompletion = 114,
4671+
tabIndex = 115,
4672+
unicodeHighlighting = 116,
4673+
unusualLineTerminators = 117,
4674+
useShadowDOM = 118,
4675+
useTabStops = 119,
4676+
wordBreak = 120,
4677+
wordSeparators = 121,
4678+
wordWrap = 122,
4679+
wordWrapBreakAfterCharacters = 123,
4680+
wordWrapBreakBeforeCharacters = 124,
4681+
wordWrapColumn = 125,
4682+
wordWrapOverride1 = 126,
4683+
wordWrapOverride2 = 127,
4684+
wrappingIndent = 128,
4685+
wrappingStrategy = 129,
4686+
showDeprecated = 130,
4687+
inlayHints = 131,
4688+
editorClassName = 132,
4689+
pixelRatio = 133,
4690+
tabFocusMode = 134,
4691+
layoutInfo = 135,
4692+
wrappingInfo = 136
46884693
}
46894694

46904695
export const EditorOptions: {
@@ -4762,6 +4767,7 @@ declare namespace monaco.editor {
47624767
multiCursorMergeOverlapping: IEditorOption<EditorOption.multiCursorMergeOverlapping, boolean>;
47634768
multiCursorModifier: IEditorOption<EditorOption.multiCursorModifier, 'altKey' | 'metaKey' | 'ctrlKey'>;
47644769
multiCursorPaste: IEditorOption<EditorOption.multiCursorPaste, 'spread' | 'full'>;
4770+
multiCursorLimit: IEditorOption<EditorOption.multiCursorLimit, number>;
47654771
occurrencesHighlight: IEditorOption<EditorOption.occurrencesHighlight, boolean>;
47664772
overviewRulerBorder: IEditorOption<EditorOption.overviewRulerBorder, boolean>;
47674773
overviewRulerLanes: IEditorOption<EditorOption.overviewRulerLanes, number>;

0 commit comments

Comments
 (0)