diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index fb2b40f1e8d..4c253a4c0f7 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -2,6 +2,7 @@ ## [UNRELEASED] +- Avoid creating a third column when opening the results view. The results view will always open to the right of the active editor, unless the active editor is in the rightmost editor column. In that case open in the leftmost column. [#1037](https://github.com/github/vscode-codeql/pull/1037) - Add a CodeLens to make the Quick Evaluation command more accessible. Click the `Quick Evaluation` prompt above a predicate definition in the editor to evaluate that predicate on its own. [#1035](https://github.com/github/vscode-codeql/pull/1035) - Fix a bug where the _Alerts_ option would show in the results view even if there is no alerts table available. [#1038](https://github.com/github/vscode-codeql/pull/1038) diff --git a/extensions/ql-vscode/src/interface.ts b/extensions/ql-vscode/src/interface.ts index 100e394173d..ed1f0b6c2a1 100644 --- a/extensions/ql-vscode/src/interface.ts +++ b/extensions/ql-vscode/src/interface.ts @@ -160,10 +160,11 @@ export class InterfaceManager extends DisposableObject { getPanel(): vscode.WebviewPanel { if (this._panel == undefined) { const { ctx } = this; + const webViewColumn = this.chooseColumnForWebview(); const panel = (this._panel = Window.createWebviewPanel( 'resultsView', // internal name 'CodeQL Query Results', // user-visible name - { viewColumn: vscode.ViewColumn.Beside, preserveFocus: true }, + { viewColumn: webViewColumn, preserveFocus: true }, { enableScripts: true, enableFindWidget: true, @@ -203,6 +204,29 @@ export class InterfaceManager extends DisposableObject { return this._panel; } + /** + * Choose where to open the webview. + * + * If there is a single view column, then open beside it. + * If there are multiple view columns, then open beside the active column, + * unless the active editor is the last column. In this case, open in the first column. + * + * The goal is to avoid opening new columns when there already are two columns open. + */ + private chooseColumnForWebview(): vscode.ViewColumn { + // This is not a great way to determine the number of view columns, but I + // can't find a vscode API that does it any better. + // Here, iterate through all the visible editors and determine the max view column. + // This won't work if the largest view column is empty. + const colCount = Window.visibleTextEditors.reduce((maxVal, editor) => + Math.max(maxVal, Number.parseInt(editor.viewColumn?.toFixed() || '0', 10)), 0); + if (colCount <= 1) { + return vscode.ViewColumn.Beside; + } + const activeViewColumnNum = Number.parseInt(Window.activeTextEditor?.viewColumn?.toFixed() || '0', 10); + return activeViewColumnNum === colCount ? vscode.ViewColumn.One : vscode.ViewColumn.Beside; + } + private async changeInterpretedSortState( sortState: InterpretedResultsSortState | undefined ): Promise {