Skip to content

Commit ba1090d

Browse files
authored
Merge pull request microsoft#149703 from SethFalco/issue-60713
feat: add setting for multi cursor limit
2 parents f80a66f + d786775 commit ba1090d

File tree

6 files changed

+170
-133
lines changed

6 files changed

+170
-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 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: 3 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;
@@ -84,6 +85,7 @@ export class CursorConfiguration {
8485
|| e.hasChanged(EditorOption.emptySelectionClipboard)
8586
|| e.hasChanged(EditorOption.multiCursorMergeOverlapping)
8687
|| e.hasChanged(EditorOption.multiCursorPaste)
88+
|| e.hasChanged(EditorOption.multiCursorLimit)
8789
|| e.hasChanged(EditorOption.autoClosingBrackets)
8890
|| e.hasChanged(EditorOption.autoClosingQuotes)
8991
|| e.hasChanged(EditorOption.autoClosingDelete)
@@ -121,6 +123,7 @@ export class CursorConfiguration {
121123
this.copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
122124
this.multiCursorMergeOverlapping = options.get(EditorOption.multiCursorMergeOverlapping);
123125
this.multiCursorPaste = options.get(EditorOption.multiCursorPaste);
126+
this.multiCursorLimit = options.get(EditorOption.multiCursorLimit);
124127
this.autoClosingBrackets = options.get(EditorOption.autoClosingBrackets);
125128
this.autoClosingQuotes = options.get(EditorOption.autoClosingQuotes);
126129
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
/**

0 commit comments

Comments
 (0)