Skip to content

Commit 25d6ecd

Browse files
authored
VS Code: Don't register Toggle Comment as global shortcut (#1409)
This pull request fixes the Herb extension from globally overriding VS Code's built-in comment commands (`editor.action.commentLine` and `editor.action.blockComment`). Previously, the extension hijacked these commands for all file types and tried to fall back to the default behavior via `default:editor.action.commentLine` for non-ERB files, but that fallback mechanism isn't reliable. Instead we register our comment actions and assign them with a shortcut in ERB files. Resolves #1405
1 parent 5ac1b52 commit 25d6ecd

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

javascript/packages/vscode/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@
139139
"icon": "$(github)",
140140
"when": "false"
141141
},
142+
{
143+
"command": "herb.toggleLineComment",
144+
"title": "Herb: Toggle Line Comment",
145+
"when": "editorLangId == erb"
146+
},
147+
{
148+
"command": "herb.toggleBlockComment",
149+
"title": "Herb: Toggle Block Comment",
150+
"when": "editorLangId == erb"
151+
},
142152
{
143153
"command": "herb.toggleLinter",
144154
"title": "Herb: Toggle Linter",
@@ -160,6 +170,20 @@
160170
"icon": "$(symbol-numeric)"
161171
}
162172
],
173+
"keybindings": [
174+
{
175+
"command": "herb.toggleLineComment",
176+
"key": "ctrl+/",
177+
"mac": "cmd+/",
178+
"when": "editorTextFocus && editorLangId == erb"
179+
},
180+
{
181+
"command": "herb.toggleBlockComment",
182+
"key": "shift+alt+a",
183+
"mac": "shift+alt+a",
184+
"when": "editorTextFocus && editorLangId == erb"
185+
}
186+
],
163187
"viewsContainers": {
164188
"activitybar": [
165189
{

javascript/packages/vscode/src/extension.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,19 @@ export async function activate(context: vscode.ExtensionContext) {
160160
await client.updateConfiguration()
161161
}),
162162

163-
vscode.commands.registerCommand('editor.action.commentLine', async () => {
163+
vscode.commands.registerCommand('herb.toggleLineComment', async () => {
164164
const editor = vscode.window.activeTextEditor
165165

166-
if (editor?.document.languageId === 'erb') {
166+
if (editor) {
167167
await sendCommentRequest(editor, 'herb/toggleLineComment')
168-
} else {
169-
await vscode.commands.executeCommand('default:editor.action.commentLine')
170168
}
171169
}),
172170

173-
vscode.commands.registerCommand('editor.action.blockComment', async () => {
171+
vscode.commands.registerCommand('herb.toggleBlockComment', async () => {
174172
const editor = vscode.window.activeTextEditor
175173

176-
if (editor?.document.languageId === 'erb') {
174+
if (editor) {
177175
await sendCommentRequest(editor, 'herb/toggleBlockComment')
178-
} else {
179-
await vscode.commands.executeCommand('default:editor.action.blockComment')
180176
}
181177
})
182178
)

0 commit comments

Comments
 (0)