From 4f8b12b13adeaaa38a7e1f8e5b022bfad3d3cb12 Mon Sep 17 00:00:00 2001 From: Asger F Date: Mon, 11 Nov 2019 11:06:40 +0000 Subject: [PATCH] Add decoration to focused item --- extensions/ql-vscode/src/interface.ts | 31 ++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/extensions/ql-vscode/src/interface.ts b/extensions/ql-vscode/src/interface.ts index da8dafded..9c9c759d1 100644 --- a/extensions/ql-vscode/src/interface.ts +++ b/extensions/ql-vscode/src/interface.ts @@ -98,6 +98,7 @@ export class InterfaceManager extends DisposableObject { super(); this.push(this._diagnosticCollection); + this.push(vscode.window.onDidChangeTextEditorSelection(this.handleSelectionChange.bind(this))); } // Returns the webview panel, creating it if it doesn't already @@ -398,16 +399,40 @@ export class InterfaceManager extends DisposableObject { sortState: info.sortState }; } + + private handleSelectionChange(event: vscode.TextEditorSelectionChangeEvent) { + if (event.kind === vscode.TextEditorSelectionChangeKind.Command) { + return; // Ignore selection events we caused ourselves. + } + let editor = vscode.window.activeTextEditor; + if (editor !== undefined) { + editor.setDecorations(shownLocationDecoration, []); + editor.setDecorations(shownLocationLineDecoration, []); + } + } } +const findMatchBackground = new vscode.ThemeColor('editor.findMatchBackground'); +const findRangeHighlightBackground = new vscode.ThemeColor('editor.findRangeHighlightBackground'); + +const shownLocationDecoration = vscode.window.createTextEditorDecorationType({ + backgroundColor: findMatchBackground, +}); + +const shownLocationLineDecoration = vscode.window.createTextEditorDecorationType({ + backgroundColor: findRangeHighlightBackground, + isWholeLine: true +}); + async function showLocation(loc: ResolvableLocationValue, databaseItem: DatabaseItem): Promise { const resolvedLocation = tryResolveLocation(loc, databaseItem); if (resolvedLocation) { const doc = await workspace.openTextDocument(resolvedLocation.uri); const editor = await Window.showTextDocument(doc, vscode.ViewColumn.One); - const sel = new vscode.Selection(resolvedLocation.range.start, resolvedLocation.range.end); - editor.selection = sel; - editor.revealRange(sel, vscode.TextEditorRevealType.InCenter); + editor.selection = new vscode.Selection(resolvedLocation.range.start, resolvedLocation.range.end); + editor.revealRange(resolvedLocation.range, vscode.TextEditorRevealType.InCenter); + editor.setDecorations(shownLocationDecoration, [resolvedLocation.range]); + editor.setDecorations(shownLocationLineDecoration, [resolvedLocation.range]); } }