Skip to content

Commit 034724a

Browse files
authored
Allow highlighting multiline selections and allow to control max length (microsoft#228982)
* add editor option for multiline selection highlights * make max length configurable for selection highlighting * 💄
1 parent 902041a commit 034724a

File tree

4 files changed

+146
-101
lines changed

4 files changed

+146
-101
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,16 @@ export interface IEditorOptions {
606606
* Defaults to true.
607607
*/
608608
selectionHighlight?: boolean;
609+
/**
610+
* Enable selection highlight for multiline selections.
611+
* Defaults to false.
612+
*/
613+
selectionHighlightMultiline?: boolean;
614+
/**
615+
* Maximum length (in characters) for selection highlights.
616+
* Set to 0 to have an unlimited length.
617+
*/
618+
selectionHighlightMaxLength?: number;
609619
/**
610620
* Enable semantic occurrences highlight.
611621
* Defaults to 'singleFile'.
@@ -5683,6 +5693,8 @@ export const enum EditorOption {
56835693
scrollPredominantAxis,
56845694
selectionClipboard,
56855695
selectionHighlight,
5696+
selectionHighlightMaxLength,
5697+
selectionHighlightMultiline,
56865698
selectOnLineNumbers,
56875699
showFoldingControls,
56885700
showUnused,
@@ -6376,6 +6388,15 @@ export const EditorOptions = {
63766388
EditorOption.selectionHighlight, 'selectionHighlight', true,
63776389
{ description: nls.localize('selectionHighlight', "Controls whether the editor should highlight matches similar to the selection.") }
63786390
)),
6391+
selectionHighlightMaxLength: register(new EditorIntOption(
6392+
EditorOption.selectionHighlightMaxLength, 'selectionHighlightMaxLength',
6393+
200, 0, Constants.MAX_SAFE_SMALL_INTEGER,
6394+
{ description: nls.localize('selectionHighlightMaxLength', "Controls how many characters can be in the selection before similiar matches are not highlighted. Set to zero for unlimited.") }
6395+
)),
6396+
selectionHighlightMultiline: register(new EditorBooleanOption(
6397+
EditorOption.selectionHighlightMultiline, 'selectionHighlightMultiline', false,
6398+
{ description: nls.localize('selectionHighlightMultiline', "Controls whether the editor should highlight selection matches that span multiple lines.") }
6399+
)),
63796400
selectOnLineNumbers: register(new EditorBooleanOption(
63806401
EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true,
63816402
)),

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

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -293,53 +293,55 @@ export enum EditorOption {
293293
scrollPredominantAxis = 116,
294294
selectionClipboard = 117,
295295
selectionHighlight = 118,
296-
selectOnLineNumbers = 119,
297-
showFoldingControls = 120,
298-
showUnused = 121,
299-
snippetSuggestions = 122,
300-
smartSelect = 123,
301-
smoothScrolling = 124,
302-
stickyScroll = 125,
303-
stickyTabStops = 126,
304-
stopRenderingLineAfter = 127,
305-
suggest = 128,
306-
suggestFontSize = 129,
307-
suggestLineHeight = 130,
308-
suggestOnTriggerCharacters = 131,
309-
suggestSelection = 132,
310-
tabCompletion = 133,
311-
tabIndex = 134,
312-
unicodeHighlighting = 135,
313-
unusualLineTerminators = 136,
314-
useShadowDOM = 137,
315-
useTabStops = 138,
316-
wordBreak = 139,
317-
wordSegmenterLocales = 140,
318-
wordSeparators = 141,
319-
wordWrap = 142,
320-
wordWrapBreakAfterCharacters = 143,
321-
wordWrapBreakBeforeCharacters = 144,
322-
wordWrapColumn = 145,
323-
wordWrapOverride1 = 146,
324-
wordWrapOverride2 = 147,
325-
wrappingIndent = 148,
326-
wrappingStrategy = 149,
327-
showDeprecated = 150,
328-
inertialScroll = 151,
329-
inlayHints = 152,
330-
wrapOnEscapedLineFeeds = 153,
331-
effectiveCursorStyle = 154,
332-
editorClassName = 155,
333-
pixelRatio = 156,
334-
tabFocusMode = 157,
335-
layoutInfo = 158,
336-
wrappingInfo = 159,
337-
defaultColorDecorators = 160,
338-
colorDecoratorsActivatedOn = 161,
339-
inlineCompletionsAccessibilityVerbose = 162,
340-
effectiveEditContext = 163,
341-
scrollOnMiddleClick = 164,
342-
effectiveAllowVariableFonts = 165
296+
selectionHighlightMaxLength = 119,
297+
selectionHighlightMultiline = 120,
298+
selectOnLineNumbers = 121,
299+
showFoldingControls = 122,
300+
showUnused = 123,
301+
snippetSuggestions = 124,
302+
smartSelect = 125,
303+
smoothScrolling = 126,
304+
stickyScroll = 127,
305+
stickyTabStops = 128,
306+
stopRenderingLineAfter = 129,
307+
suggest = 130,
308+
suggestFontSize = 131,
309+
suggestLineHeight = 132,
310+
suggestOnTriggerCharacters = 133,
311+
suggestSelection = 134,
312+
tabCompletion = 135,
313+
tabIndex = 136,
314+
unicodeHighlighting = 137,
315+
unusualLineTerminators = 138,
316+
useShadowDOM = 139,
317+
useTabStops = 140,
318+
wordBreak = 141,
319+
wordSegmenterLocales = 142,
320+
wordSeparators = 143,
321+
wordWrap = 144,
322+
wordWrapBreakAfterCharacters = 145,
323+
wordWrapBreakBeforeCharacters = 146,
324+
wordWrapColumn = 147,
325+
wordWrapOverride1 = 148,
326+
wordWrapOverride2 = 149,
327+
wrappingIndent = 150,
328+
wrappingStrategy = 151,
329+
showDeprecated = 152,
330+
inertialScroll = 153,
331+
inlayHints = 154,
332+
wrapOnEscapedLineFeeds = 155,
333+
effectiveCursorStyle = 156,
334+
editorClassName = 157,
335+
pixelRatio = 158,
336+
tabFocusMode = 159,
337+
layoutInfo = 160,
338+
wrappingInfo = 161,
339+
defaultColorDecorators = 162,
340+
colorDecoratorsActivatedOn = 163,
341+
inlineCompletionsAccessibilityVerbose = 164,
342+
effectiveEditContext = 165,
343+
scrollOnMiddleClick = 166,
344+
effectiveAllowVariableFonts = 167
343345
}
344346

345347
/**

src/vs/editor/contrib/multicursor/browser/multicursor.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
839839

840840
private readonly editor: ICodeEditor;
841841
private _isEnabled: boolean;
842+
private _isEnabledMultiline: boolean;
843+
private _maxLength: number;
842844
private readonly _decorations: IEditorDecorationsCollection;
843845
private readonly updateSoon: RunOnceScheduler;
844846
private state: SelectionHighlighterState | null;
@@ -850,12 +852,16 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
850852
super();
851853
this.editor = editor;
852854
this._isEnabled = editor.getOption(EditorOption.selectionHighlight);
855+
this._isEnabledMultiline = editor.getOption(EditorOption.selectionHighlightMultiline);
856+
this._maxLength = editor.getOption(EditorOption.selectionHighlightMaxLength);
853857
this._decorations = editor.createDecorationsCollection();
854858
this.updateSoon = this._register(new RunOnceScheduler(() => this._update(), 300));
855859
this.state = null;
856860

857861
this._register(editor.onDidChangeConfiguration((e) => {
858862
this._isEnabled = editor.getOption(EditorOption.selectionHighlight);
863+
this._isEnabledMultiline = editor.getOption(EditorOption.selectionHighlightMultiline);
864+
this._maxLength = editor.getOption(EditorOption.selectionHighlightMaxLength);
859865
}));
860866
this._register(editor.onDidChangeCursorSelection((e: ICursorSelectionChangedEvent) => {
861867

@@ -897,20 +903,22 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
897903
}
898904

899905
private _update(): void {
900-
this._setState(SelectionHighlighter._createState(this.state, this._isEnabled, this.editor));
906+
this._setState(SelectionHighlighter._createState(this.state, this._isEnabled, this._isEnabledMultiline, this._maxLength, this.editor));
901907
}
902908

903-
private static _createState(oldState: SelectionHighlighterState | null, isEnabled: boolean, editor: ICodeEditor): SelectionHighlighterState | null {
909+
private static _createState(oldState: SelectionHighlighterState | null, isEnabled: boolean, isEnabledMultiline: boolean, maxLength: number, editor: ICodeEditor): SelectionHighlighterState | null {
904910
if (!isEnabled) {
905911
return null;
906912
}
907913
if (!editor.hasModel()) {
908914
return null;
909915
}
910-
const s = editor.getSelection();
911-
if (s.startLineNumber !== s.endLineNumber) {
912-
// multiline forbidden for perf reasons
913-
return null;
916+
if (!isEnabledMultiline) {
917+
const s = editor.getSelection();
918+
if (s.startLineNumber !== s.endLineNumber) {
919+
// multiline forbidden for perf reasons
920+
return null;
921+
}
914922
}
915923
const multiCursorController = MultiCursorSelectionController.get(editor);
916924
if (!multiCursorController) {
@@ -947,7 +955,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
947955
// whitespace only selection
948956
return null;
949957
}
950-
if (r.searchText.length > 200) {
958+
if (maxLength > 0 && r.searchText.length > maxLength) {
951959
// very long selection
952960
return null;
953961
}

src/vs/monaco.d.ts

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,6 +3739,16 @@ declare namespace monaco.editor {
37393739
* Defaults to true.
37403740
*/
37413741
selectionHighlight?: boolean;
3742+
/**
3743+
* Enable selection highlight for multiline selections.
3744+
* Defaults to false.
3745+
*/
3746+
selectionHighlightMultiline?: boolean;
3747+
/**
3748+
* Maximum length (in characters) for selection highlights.
3749+
* Set to 0 to have an unlimited length.
3750+
*/
3751+
selectionHighlightMaxLength?: number;
37423752
/**
37433753
* Enable semantic occurrences highlight.
37443754
* Defaults to 'singleFile'.
@@ -5131,53 +5141,55 @@ declare namespace monaco.editor {
51315141
scrollPredominantAxis = 116,
51325142
selectionClipboard = 117,
51335143
selectionHighlight = 118,
5134-
selectOnLineNumbers = 119,
5135-
showFoldingControls = 120,
5136-
showUnused = 121,
5137-
snippetSuggestions = 122,
5138-
smartSelect = 123,
5139-
smoothScrolling = 124,
5140-
stickyScroll = 125,
5141-
stickyTabStops = 126,
5142-
stopRenderingLineAfter = 127,
5143-
suggest = 128,
5144-
suggestFontSize = 129,
5145-
suggestLineHeight = 130,
5146-
suggestOnTriggerCharacters = 131,
5147-
suggestSelection = 132,
5148-
tabCompletion = 133,
5149-
tabIndex = 134,
5150-
unicodeHighlighting = 135,
5151-
unusualLineTerminators = 136,
5152-
useShadowDOM = 137,
5153-
useTabStops = 138,
5154-
wordBreak = 139,
5155-
wordSegmenterLocales = 140,
5156-
wordSeparators = 141,
5157-
wordWrap = 142,
5158-
wordWrapBreakAfterCharacters = 143,
5159-
wordWrapBreakBeforeCharacters = 144,
5160-
wordWrapColumn = 145,
5161-
wordWrapOverride1 = 146,
5162-
wordWrapOverride2 = 147,
5163-
wrappingIndent = 148,
5164-
wrappingStrategy = 149,
5165-
showDeprecated = 150,
5166-
inertialScroll = 151,
5167-
inlayHints = 152,
5168-
wrapOnEscapedLineFeeds = 153,
5169-
effectiveCursorStyle = 154,
5170-
editorClassName = 155,
5171-
pixelRatio = 156,
5172-
tabFocusMode = 157,
5173-
layoutInfo = 158,
5174-
wrappingInfo = 159,
5175-
defaultColorDecorators = 160,
5176-
colorDecoratorsActivatedOn = 161,
5177-
inlineCompletionsAccessibilityVerbose = 162,
5178-
effectiveEditContext = 163,
5179-
scrollOnMiddleClick = 164,
5180-
effectiveAllowVariableFonts = 165
5144+
selectionHighlightMaxLength = 119,
5145+
selectionHighlightMultiline = 120,
5146+
selectOnLineNumbers = 121,
5147+
showFoldingControls = 122,
5148+
showUnused = 123,
5149+
snippetSuggestions = 124,
5150+
smartSelect = 125,
5151+
smoothScrolling = 126,
5152+
stickyScroll = 127,
5153+
stickyTabStops = 128,
5154+
stopRenderingLineAfter = 129,
5155+
suggest = 130,
5156+
suggestFontSize = 131,
5157+
suggestLineHeight = 132,
5158+
suggestOnTriggerCharacters = 133,
5159+
suggestSelection = 134,
5160+
tabCompletion = 135,
5161+
tabIndex = 136,
5162+
unicodeHighlighting = 137,
5163+
unusualLineTerminators = 138,
5164+
useShadowDOM = 139,
5165+
useTabStops = 140,
5166+
wordBreak = 141,
5167+
wordSegmenterLocales = 142,
5168+
wordSeparators = 143,
5169+
wordWrap = 144,
5170+
wordWrapBreakAfterCharacters = 145,
5171+
wordWrapBreakBeforeCharacters = 146,
5172+
wordWrapColumn = 147,
5173+
wordWrapOverride1 = 148,
5174+
wordWrapOverride2 = 149,
5175+
wrappingIndent = 150,
5176+
wrappingStrategy = 151,
5177+
showDeprecated = 152,
5178+
inertialScroll = 153,
5179+
inlayHints = 154,
5180+
wrapOnEscapedLineFeeds = 155,
5181+
effectiveCursorStyle = 156,
5182+
editorClassName = 157,
5183+
pixelRatio = 158,
5184+
tabFocusMode = 159,
5185+
layoutInfo = 160,
5186+
wrappingInfo = 161,
5187+
defaultColorDecorators = 162,
5188+
colorDecoratorsActivatedOn = 163,
5189+
inlineCompletionsAccessibilityVerbose = 164,
5190+
effectiveEditContext = 165,
5191+
scrollOnMiddleClick = 166,
5192+
effectiveAllowVariableFonts = 167
51815193
}
51825194

51835195
export const EditorOptions: {
@@ -5304,6 +5316,8 @@ declare namespace monaco.editor {
53045316
scrollPredominantAxis: IEditorOption<EditorOption.scrollPredominantAxis, boolean>;
53055317
selectionClipboard: IEditorOption<EditorOption.selectionClipboard, boolean>;
53065318
selectionHighlight: IEditorOption<EditorOption.selectionHighlight, boolean>;
5319+
selectionHighlightMaxLength: IEditorOption<EditorOption.selectionHighlightMaxLength, number>;
5320+
selectionHighlightMultiline: IEditorOption<EditorOption.selectionHighlightMultiline, boolean>;
53075321
selectOnLineNumbers: IEditorOption<EditorOption.selectOnLineNumbers, boolean>;
53085322
showFoldingControls: IEditorOption<EditorOption.showFoldingControls, 'always' | 'never' | 'mouseover'>;
53095323
showUnused: IEditorOption<EditorOption.showUnused, boolean>;

0 commit comments

Comments
 (0)