Skip to content

Commit

Permalink
Activate views before triggering command and create shortcut on eligi…
Browse files Browse the repository at this point in the history
…ble file editors
  • Loading branch information
JennieJi committed Mar 5, 2023
1 parent 76659ec commit 4daad6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"commands": [
{
"command": "babelAstExplorer.start",
"title": "Open",
"title": "Show AST",
"category": "Babel AST Explorer",
"icon": "$(triangle-right)"
"icon": "resources/icons/babel-logo-minimal.svg"
},
{
"command": "babelAstExplorer.update",
Expand All @@ -49,11 +49,11 @@
"when": "false"
}
],
"view/title": [
"editor/title": [
{
"command": "babelAstExplorer.start",
"when": "view =~ /babelAstExplorer/",
"group": "navigation@2"
"group": "navigation@1",
"when": "editorLangId == 'typescript' || editorLangId == 'typescriptreact' || editorLangId == 'javascript' || editorLangId == 'javascriptreact'"
}
]
},
Expand Down
26 changes: 7 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,21 @@ import guessPlugins from './guessPlugins';

export function activate(context: vscode.ExtensionContext) {
let astView: ASTView | undefined;
let optionsView: OptionsView | undefined;
const defaultOptions = OPTIONS.map(({ value }) => value);
const optionsView = new OptionsView({
options: defaultOptions
});

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.start, () => {
const plugins = guessPlugins(vscode.window.activeTextEditor);
if (optionsView) {
optionsView.update({ plugins })
} else {
optionsView = new OptionsView({
options: defaultOptions,
plugins,
});
}
optionsView.update({ plugins });
if (astView) {
astView.update({ plugins });
} else {
astView = new ASTView(
() => {
if (optionsView) {
optionsView.dispose();
optionsView = undefined;
}
astView = undefined;
optionsView.dispose();
},
{ options: defaultOptions, plugins }
);
Expand All @@ -41,12 +32,9 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(
COMMANDS.update,
(options: ASTViewOptions) => {

optionsView.update(options);
if (astView) {
astView.updateOptions(options);
}
if (optionsView) {
optionsView.update(options);
astView.update(options);
}
}
)
Expand Down

0 comments on commit 4daad6a

Please sign in to comment.