Skip to content

Commit 0c45210

Browse files
committed
Treat single-line and multi-line ranges differently
1 parent 4f8b12b commit 0c45210

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,24 @@ async function showLocation(loc: ResolvableLocationValue, databaseItem: Database
429429
if (resolvedLocation) {
430430
const doc = await workspace.openTextDocument(resolvedLocation.uri);
431431
const editor = await Window.showTextDocument(doc, vscode.ViewColumn.One);
432-
editor.selection = new vscode.Selection(resolvedLocation.range.start, resolvedLocation.range.end);
433-
editor.revealRange(resolvedLocation.range, vscode.TextEditorRevealType.InCenter);
434-
editor.setDecorations(shownLocationDecoration, [resolvedLocation.range]);
435-
editor.setDecorations(shownLocationLineDecoration, [resolvedLocation.range]);
432+
let range = resolvedLocation.range;
433+
// When highlighting the range, vscode's occurrence-match and bracket-match highlighting will
434+
// trigger based on where we place the cursor/selection, and will compete for the user's attention.
435+
// For reference:
436+
// - Occurences are highlighted when the cursor is next to or inside a word or a whole word is selected.
437+
// - Brackets are highlighted when the cursor is next to a bracket and there is a non-empty selection.
438+
// - Multi-line selections explicitly highlight line-break characters, but multi-line decorators do not.
439+
//
440+
// For single-line ranges, select the whole range, mainly to disable bracket highlighting.
441+
// For multi-line ranges, place the cursor at the beginning to avoid visual artifacts from selected line-breaks.
442+
// Multi-line ranges are usually large enough to overshadow the noise from bracket highlighting.
443+
let selectionEnd = (range.start.line === range.end.line)
444+
? range.end
445+
: range.start;
446+
editor.selection = new vscode.Selection(range.start, selectionEnd);
447+
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
448+
editor.setDecorations(shownLocationDecoration, [range]);
449+
editor.setDecorations(shownLocationLineDecoration, [range]);
436450
}
437451
}
438452

0 commit comments

Comments
 (0)