Skip to content

Commit

Permalink
Fix run button visibility logic (#1319)
Browse files Browse the repository at this point in the history
## Changes
- Update custom context for the run button on startup
- Update it when the active folder changes
  • Loading branch information
ilia-db authored Aug 21, 2024
1 parent dadffd7 commit efcb26b
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
QuickPickItem,
QuickPickItemKind,
StatusBarAlignment,
TextEditor,
WorkspaceFolder,
window,
workspace,
Expand Down Expand Up @@ -34,6 +35,8 @@ export class WorkspaceFolderManager implements Disposable {
this.button.show();
}

this.setIsActiveFileInActiveWorkspace(window.activeTextEditor);

this.disposables.push(
this.button,
workspace.onDidChangeWorkspaceFolders((e) => {
Expand All @@ -51,20 +54,27 @@ export class WorkspaceFolderManager implements Disposable {
return;
}
}),
window.onDidChangeActiveTextEditor((e) => {
const isActiveFileInActiveWorkspace =
this.activeWorkspaceFolder !== undefined &&
e !== undefined &&
e.document.uri.fsPath.startsWith(
this.activeWorkspaceFolder?.uri.fsPath
);
customWhenContext.setIsActiveFileInActiveWorkspace(
isActiveFileInActiveWorkspace
);
window.onDidChangeActiveTextEditor((editor) => {
this.setIsActiveFileInActiveWorkspace(editor);
}),
this.onDidChangeActiveWorkspaceFolder(() => {
this.setIsActiveFileInActiveWorkspace(window.activeTextEditor);
})
);
}

private setIsActiveFileInActiveWorkspace(activeEditor?: TextEditor) {
const isActiveFileInActiveWorkspace =
this.activeWorkspaceFolder !== undefined &&
activeEditor !== undefined &&
activeEditor.document.uri.fsPath.startsWith(
this.activeWorkspaceFolder?.uri.fsPath
);
this.customWhenContext.setIsActiveFileInActiveWorkspace(
isActiveFileInActiveWorkspace
);
}

get activeWorkspaceFolder() {
if (this._activeWorkspaceFolder === undefined) {
throw new Error("No active workspace folder");
Expand Down

0 comments on commit efcb26b

Please sign in to comment.