wmaurer/vscode-change-case

Critical bug: Incorrect state handling

Opened this issue · 0 comments

V. 1.0.0:

The commands “Change Case…” remain accessible even if no text editor is active, for example, when the active tab document is a bitmap image. In this case, then the error message is

Cannot destructure property 'document' of 'editor' as it is undefined.

Possible solution:

  • Use when clause in “package.json“, in this clause, use the context property. In the extension code, set the value of this property to true of false using vscode.commands.executeCommand("setContext", state). To figure out the state, find out if a text editor is active, and, optionally, if it has selected text. Also, use menus > commandPalette in “package.json“, list your commands with the same when clause there.

  • Instead of vscode.commands.registerCommand, use vscode.commands.registerTextEditorCommand. It should be enough for all commands except "extension.changeCase.commands".

  • Use context.subscriptions.push for all disposable objects, first of all, for commands.

Thank you.
—SA