Skip to content

Commit 4f8b12b

Browse files
committed
Add decoration to focused item
1 parent 9e9b49c commit 4f8b12b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class InterfaceManager extends DisposableObject {
9898

9999
super();
100100
this.push(this._diagnosticCollection);
101+
this.push(vscode.window.onDidChangeTextEditorSelection(this.handleSelectionChange.bind(this)));
101102
}
102103

103104
// Returns the webview panel, creating it if it doesn't already
@@ -398,16 +399,40 @@ export class InterfaceManager extends DisposableObject {
398399
sortState: info.sortState
399400
};
400401
}
402+
403+
private handleSelectionChange(event: vscode.TextEditorSelectionChangeEvent) {
404+
if (event.kind === vscode.TextEditorSelectionChangeKind.Command) {
405+
return; // Ignore selection events we caused ourselves.
406+
}
407+
let editor = vscode.window.activeTextEditor;
408+
if (editor !== undefined) {
409+
editor.setDecorations(shownLocationDecoration, []);
410+
editor.setDecorations(shownLocationLineDecoration, []);
411+
}
412+
}
401413
}
402414

415+
const findMatchBackground = new vscode.ThemeColor('editor.findMatchBackground');
416+
const findRangeHighlightBackground = new vscode.ThemeColor('editor.findRangeHighlightBackground');
417+
418+
const shownLocationDecoration = vscode.window.createTextEditorDecorationType({
419+
backgroundColor: findMatchBackground,
420+
});
421+
422+
const shownLocationLineDecoration = vscode.window.createTextEditorDecorationType({
423+
backgroundColor: findRangeHighlightBackground,
424+
isWholeLine: true
425+
});
426+
403427
async function showLocation(loc: ResolvableLocationValue, databaseItem: DatabaseItem): Promise<void> {
404428
const resolvedLocation = tryResolveLocation(loc, databaseItem);
405429
if (resolvedLocation) {
406430
const doc = await workspace.openTextDocument(resolvedLocation.uri);
407431
const editor = await Window.showTextDocument(doc, vscode.ViewColumn.One);
408-
const sel = new vscode.Selection(resolvedLocation.range.start, resolvedLocation.range.end);
409-
editor.selection = sel;
410-
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter);
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]);
411436
}
412437
}
413438

0 commit comments

Comments
 (0)