Skip to content

Commit c0cadf2

Browse files
author
Akos Kitta
committed
comment/uncomment line
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 939a905 commit c0cadf2

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import { UploadSketch } from './contributions/upload-sketch';
9898
import { CommonFrontendContribution } from './customization/core/common-frontend-contribution';
9999
import { CopyToForum } from './contributions/copy-to-forum';
100100
import { GoToLine } from './contributions/go-to-line';
101+
import { ToggleComment } from './contributions/toggle-comment';
101102

102103
const ElementQueries = require('css-element-queries/src/ElementQueries');
103104

@@ -328,4 +329,5 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
328329
Contribution.configure(bind, UploadSketch);
329330
Contribution.configure(bind, CopyToForum);
330331
Contribution.configure(bind, GoToLine);
332+
Contribution.configure(bind, ToggleComment);
331333
});

arduino-ide-extension/src/browser/contributions/contribution.ts

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ export abstract class EditorContribution extends Contribution {
8787
return editor instanceof MonacoEditor ? editor : undefined;
8888
}
8989

90+
protected async run(commandId: string): Promise<any> {
91+
const editor = await this.current();
92+
if (editor) {
93+
const action = editor.getControl().getAction(commandId);
94+
if (action) {
95+
return action.run();
96+
}
97+
}
98+
}
99+
90100
}
91101

92102
export namespace Contribution {

arduino-ide-extension/src/browser/contributions/go-to-line.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export class GoToLine extends EditorContribution {
2727
}
2828

2929
async goToLine(): Promise<void> {
30-
const editor = await this.current();
31-
if (editor) {
32-
const action = editor.getControl().getAction('editor.action.gotoLine');
33-
return action.run();
34-
}
30+
return this.run('editor.action.gotoLine');
3531
}
3632

3733
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { injectable } from 'inversify';
2+
import { EditorContribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
3+
import { ArduinoMenus } from '../menu/arduino-menus';
4+
5+
@injectable()
6+
export class ToggleComment extends EditorContribution {
7+
8+
registerCommands(registry: CommandRegistry): void {
9+
registry.registerCommand(ToggleComment.Commands.TOGGLE_COMMENT, {
10+
execute: () => this.toggleComment()
11+
});
12+
}
13+
14+
registerMenus(registry: MenuModelRegistry): void {
15+
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
16+
commandId: ToggleComment.Commands.TOGGLE_COMMENT.id,
17+
label: 'Comment/Uncomment',
18+
order: '0'
19+
});
20+
}
21+
22+
registerKeybindings(registry: KeybindingRegistry): void {
23+
registry.registerKeybinding({
24+
command: ToggleComment.Commands.TOGGLE_COMMENT.id,
25+
keybinding: 'CtrlCmd+L'
26+
});
27+
}
28+
29+
async toggleComment(): Promise<void> {
30+
return this.run('editor.action.commentLine');
31+
}
32+
33+
}
34+
35+
export namespace ToggleComment {
36+
export namespace Commands {
37+
export const TOGGLE_COMMENT: Command = {
38+
id: 'arduino-toggle-comment'
39+
};
40+
}
41+
}

0 commit comments

Comments
 (0)