Skip to content

Commit 28ee5c7

Browse files
committed
#20: added toggle command
1 parent 1f1504f commit 28ee5c7

File tree

7 files changed

+56
-9
lines changed

7 files changed

+56
-9
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: npm i
2222

2323
- name: Publish
24-
run: npx vsce publish -p ${{ secrets.VSCE_PAT }}
24+
run: npx @vscode/vsce publish -p ${{ secrets.VSCE_PAT }}
2525

2626
- name: Publish to open-vsx.org
2727
run: npx ovsx publish -p ${{ secrets.OPEN_VSX_PAT }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the "eliostruyf.vscode-hide-comments" extension will be documented in this file.
44

5+
## [1.7.0]
6+
7+
- [#20](https://github.com/estruyf/vscode-hide-comments/issues/20): Added a new command to tollgle the show/hide of all comments - `Hide Comments: Toggle the show/hide of all comments`
8+
59
## [1.6.0]
610

711
- [#15](https://github.com/estruyf/vscode-hide-comments/issues/15): Add `Hide Comments: Show lines by regex` and `Hide Comments: hide lines by regex` commands.

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
<p align="center">
1010
<a href="https://marketplace.visualstudio.com/items?itemName=eliostruyf.vscode-hide-comments" title="Check it out on the Visual Studio Marketplace">
11-
<img src="https://vsmarketplacebadge.apphb.com/version/eliostruyf.vscode-hide-comments.svg" alt="Visual Studio Marketplace" style="display: inline-block" />
11+
<img src="https://vsmarketplacebadges.dev/version/eliostruyf.vscode-hide-comments.svg" alt="Visual Studio Marketplace" style="display: inline-block" />
1212
</a>
1313

14-
<img src="https://vsmarketplacebadge.apphb.com/installs/eliostruyf.vscode-hide-comments.svg" alt="Number of installs" style="display: inline-block;margin-left:10px" />
14+
<img src="https://vsmarketplacebadges.dev/installs/eliostruyf.vscode-hide-comments.svg" alt="Number of installs" style="display: inline-block;margin-left:10px" />
1515

16-
<img src="https://vsmarketplacebadge.apphb.com/rating/eliostruyf.vscode-hide-comments.svg" alt="Ratings" style="display: inline-block;margin-left:10px" />
16+
<img src="https://vsmarketplacebadges.dev/rating/eliostruyf.vscode-hide-comments.svg" alt="Ratings" style="display: inline-block;margin-left:10px" />
1717

1818
<a href="https://www.buymeacoffee.com/zMeFRy9" title="Buy me a coffee" style="margin-left:10px">
1919
<img src="https://img.shields.io/badge/Buy%20me%20a%20coffee-€%203-blue?logo=buy-me-a-coffee&style=flat" alt="Buy me a coffee" style="display: inline-block" />
@@ -52,10 +52,21 @@ On the editor title, a toggle action is available to show/hide the comments quic
5252

5353
The extension currently has the following commands:
5454

55-
1. `Hide Comments: Hide all comments`
56-
2. `Hide Comments: Show all comments`
57-
3. `Hide Comments: Show lines by regex`: this command is only available when the `hideComments.regex` setting is set.
58-
4. `Hide Comments: hide lines by regex`: this command is only available when the `hideComments.regex` setting is set.
55+
1. `Hide Comments: Toggle the show/hide of all comments`
56+
2. `Hide Comments: Hide all comments`
57+
3. `Hide Comments: Show all comments`
58+
4. `Hide Comments: Show lines by regex`: this command is only available when the `hideComments.regex` setting is set.
59+
5. `Hide Comments: hide lines by regex`: this command is only available when the `hideComments.regex` setting is set.
60+
61+
### Keybindings
62+
63+
The extension does not have any default keybindings. You can add your own keybindings to the commands from within Visual Studio Code it UI. Steps to do this:
64+
65+
1. Open the command palette: `Ctrl+Shift+P` or `Cmd+Shift+P`;
66+
2. Type the command you want to add a keybinding. Example: `Hide Comments: Toggle the show/hide of all comments`;
67+
3. Click on the gear icon next to the command in the command palette. This opens the keyboard shortcuts editor;
68+
4. Add your keybinding and you are all set.
69+
5970

6071
## Hide additional lines by regex
6172

@@ -93,6 +104,6 @@ Please submit them via creating an issue in the project repository: [issue list]
93104

94105
<p align="center">
95106
<a href="#">
96-
<img src="https://estruyf-github.azurewebsites.net/api/VisitorHit?user=estruyf&repo=vscode-hide-comments&countColor=%23F141A8&labelColor=%230E131F" />
107+
<img src="https://api.visitorbadge.io/api/VisitorHit?user=estruyf&repo=vscode-hide-comments&countColor=%23F141A8&labelColor=%230E131F" />
97108
</a>
98109
</p>

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
}
8888
},
8989
"commands": [
90+
{
91+
"command": "hidecomments.toggle",
92+
"title": "Hide Comments: Toggle the show/hide of all comments"
93+
},
9094
{
9195
"command": "hidecomments.hide",
9296
"title": "Hide Comments: Hide all comments",

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode';
44
import { setComments } from './utils/setComments';
55
import { setRegexLines } from './utils/setRegexLines';
66
import { triggerCommentsHide } from './utils/triggerCommentsHide';
7+
import { toggleComments } from './utils/toggleComments';
78

89
export const CONFIG_SECTION = "hideComments";
910
export const CONFIG_DEFAULT_ENABLED = "defaultEnabled";
@@ -54,6 +55,11 @@ export async function activate(context: vscode.ExtensionContext) {
5455
await ext.setState(STATE_KEYS.regexEnabled, false);
5556
}
5657

58+
const toggleCommentsCmd = vscode.commands.registerCommand('hidecomments.toggle', async () => {
59+
toggleComments();
60+
});
61+
62+
5763
const hideCommentsCmd = vscode.commands.registerCommand('hidecomments.hide', () => {
5864
setComments(true);
5965
});
@@ -90,6 +96,7 @@ export async function activate(context: vscode.ExtensionContext) {
9096
}
9197
}, null, context.subscriptions);
9298

99+
subscriptions.push(toggleCommentsCmd);
93100
subscriptions.push(hideCommentsCmd);
94101
subscriptions.push(showCommentsCmd);
95102
subscriptions.push(hideConsoleCmd);

src/utils/setComments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const setComments = async (enabled: boolean) => {
1919
} else {
2020
textMateRules.push({
2121
"scope": [
22+
"hidecomments",
2223
"comment",
2324
"comment.block",
2425
"comment.line",

src/utils/toggleComments.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { setComments } from './setComments';
2+
import { workspace } from "vscode";
3+
import { CONFIG_TOKENS } from "../extension";
4+
5+
6+
export const toggleComments = async () => {
7+
const config = workspace.getConfiguration("editor");
8+
const colors = config.get<any>(CONFIG_TOKENS);
9+
10+
if (config && colors) {
11+
let textMateRules: any[] = colors["textMateRules"] || [];
12+
let commentRuleIdx = textMateRules.findIndex(r => r && r.scope && (r.scope as any[]).includes("comment.line.double-slash") && (r.scope as any[]).includes("hidecomments"));
13+
14+
if (commentRuleIdx >= 0) {
15+
setComments(false);
16+
} else {
17+
setComments(true);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)