Skip to content

Commit

Permalink
Fixes #5351: Add editor.occurrencesHighlight option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Mar 1, 2017
1 parent e729226 commit f886259
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class InternalEditorOptionsHelper {
suggestFontSize: opts.suggestFontSize,
suggestLineHeight: opts.suggestLineHeight,
selectionHighlight: toBoolean(opts.selectionHighlight),
occurrencesHighlight: toBoolean(opts.occurrencesHighlight),
codeLens: opts.referenceInfos && opts.codeLens,
folding: toBoolean(opts.folding),
matchBrackets: toBoolean(opts.matchBrackets),
Expand Down Expand Up @@ -797,6 +798,11 @@ const editorConfiguration: IConfigurationNode = {
'default': DefaultConfig.editor.selectionHighlight,
'description': nls.localize('selectionHighlight', "Controls whether the editor should highlight similar matches to the selection")
},
'editor.occurrencesHighlight': {
'type': 'boolean',
'default': DefaultConfig.editor.occurrencesHighlight,
'description': nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences")
},
'editor.overviewRulerLanes': {
'type': 'integer',
'default': 3,
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ConfigClass implements IConfiguration {
suggestFontSize: 0,
suggestLineHeight: 0,
selectionHighlight: true,
occurrencesHighlight: true,
codeLens: true,
referenceInfos: true,
folding: true,
Expand Down
9 changes: 9 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ export interface IEditorOptions {
* Defaults to true.
*/
selectionHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
*/
occurrencesHighlight?: boolean;
/**
* Show code lens
* Defaults to true.
Expand Down Expand Up @@ -996,6 +1001,7 @@ export class EditorContribOptions {
readonly suggestFontSize: number;
readonly suggestLineHeight: number;
readonly selectionHighlight: boolean;
readonly occurrencesHighlight: boolean;
readonly codeLens: boolean;
readonly folding: boolean;
readonly matchBrackets: boolean;
Expand All @@ -1022,6 +1028,7 @@ export class EditorContribOptions {
suggestFontSize: number;
suggestLineHeight: number;
selectionHighlight: boolean;
occurrencesHighlight: boolean;
codeLens: boolean;
folding: boolean;
matchBrackets: boolean;
Expand All @@ -1044,6 +1051,7 @@ export class EditorContribOptions {
this.suggestFontSize = source.suggestFontSize;
this.suggestLineHeight = source.suggestLineHeight;
this.selectionHighlight = Boolean(source.selectionHighlight);
this.occurrencesHighlight = Boolean(source.occurrencesHighlight);
this.codeLens = Boolean(source.codeLens);
this.folding = Boolean(source.folding);
this.matchBrackets = Boolean(source.matchBrackets);
Expand Down Expand Up @@ -1072,6 +1080,7 @@ export class EditorContribOptions {
&& this.suggestFontSize === other.suggestFontSize
&& this.suggestLineHeight === other.suggestLineHeight
&& this.selectionHighlight === other.selectionHighlight
&& this.occurrencesHighlight === other.occurrencesHighlight
&& this.codeLens === other.codeLens
&& this.folding === other.folding
&& this.matchBrackets === other.matchBrackets
Expand Down
15 changes: 15 additions & 0 deletions src/vs/editor/contrib/wordHighlighter/common/wordHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CommonEditorRegistry.registerDefaultLanguageCommand('_executeDocumentHighlights'
class WordHighlighter {

private editor: editorCommon.ICommonCodeEditor;
private occurrencesHighlight: boolean;
private model: editorCommon.IModel;
private _lastWordRange: Range;
private _decorationIds: string[];
Expand All @@ -64,6 +65,7 @@ class WordHighlighter {

constructor(editor: editorCommon.ICommonCodeEditor) {
this.editor = editor;
this.occurrencesHighlight = this.editor.getConfiguration().contribInfo.occurrencesHighlight;
this.model = this.editor.getModel();
this.toUnhook = [];
this.toUnhook.push(editor.onDidChangeCursorPosition((e: editorCommon.ICursorPositionChangedEvent) => {
Expand All @@ -76,6 +78,13 @@ class WordHighlighter {
this.toUnhook.push(editor.onDidChangeModelContent((e) => {
this._stopAll();
}));
this.toUnhook.push(editor.onDidChangeConfiguration((e) => {
let newValue = this.editor.getConfiguration().contribInfo.occurrencesHighlight;
if (this.occurrencesHighlight !== newValue) {
this.occurrencesHighlight = newValue;
this._stopAll();
}
}));

this._lastWordRange = null;
this._decorationIds = [];
Expand Down Expand Up @@ -121,6 +130,12 @@ class WordHighlighter {

private _onPositionChanged(e: editorCommon.ICursorPositionChangedEvent): void {

// disabled
if (!this.occurrencesHighlight) {
this._stopAll();
return;
}

// ignore typing & other
if (e.reason !== editorCommon.CursorChangeReason.Explicit) {
this._stopAll();
Expand Down
6 changes: 6 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,11 @@ declare module monaco.editor {
* Defaults to true.
*/
selectionHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
*/
occurrencesHighlight?: boolean;
/**
* Show code lens
* Defaults to true.
Expand Down Expand Up @@ -1612,6 +1617,7 @@ declare module monaco.editor {
readonly suggestFontSize: number;
readonly suggestLineHeight: number;
readonly selectionHighlight: boolean;
readonly occurrencesHighlight: boolean;
readonly codeLens: boolean;
readonly folding: boolean;
readonly matchBrackets: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/telemetry/common/telemetryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const configurationValueWhitelist = [
'editor.quickSuggestionsDelay',
'editor.snippetSuggestions',
'editor.selectionHighlight',
'editor.occurrencesHighlight',
'editor.glyphMargin',
'editor.wordSeparators',
'editor.mouseWheelScrollSensitivity',
Expand Down

0 comments on commit f886259

Please sign in to comment.