comment/uncomment line

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-18 14:57:25 +02:00
parent 939a905a6b
commit c0cadf2b9b
4 changed files with 54 additions and 5 deletions

View File

@ -98,6 +98,7 @@ import { UploadSketch } from './contributions/upload-sketch';
import { CommonFrontendContribution } from './customization/core/common-frontend-contribution';
import { CopyToForum } from './contributions/copy-to-forum';
import { GoToLine } from './contributions/go-to-line';
import { ToggleComment } from './contributions/toggle-comment';
const ElementQueries = require('css-element-queries/src/ElementQueries');
@ -328,4 +329,5 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
Contribution.configure(bind, UploadSketch);
Contribution.configure(bind, CopyToForum);
Contribution.configure(bind, GoToLine);
Contribution.configure(bind, ToggleComment);
});

View File

@ -87,6 +87,16 @@ export abstract class EditorContribution extends Contribution {
return editor instanceof MonacoEditor ? editor : undefined;
}
protected async run(commandId: string): Promise<any> {
const editor = await this.current();
if (editor) {
const action = editor.getControl().getAction(commandId);
if (action) {
return action.run();
}
}
}
}
export namespace Contribution {

View File

@ -27,11 +27,7 @@ export class GoToLine extends EditorContribution {
}
async goToLine(): Promise<void> {
const editor = await this.current();
if (editor) {
const action = editor.getControl().getAction('editor.action.gotoLine');
return action.run();
}
return this.run('editor.action.gotoLine');
}
}

View File

@ -0,0 +1,41 @@
import { injectable } from 'inversify';
import { EditorContribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus';
@injectable()
export class ToggleComment extends EditorContribution {
registerCommands(registry: CommandRegistry): void {
registry.registerCommand(ToggleComment.Commands.TOGGLE_COMMENT, {
execute: () => this.toggleComment()
});
}
registerMenus(registry: MenuModelRegistry): void {
registry.registerMenuAction(ArduinoMenus.EDIT__CODE_CONTROL_GROUP, {
commandId: ToggleComment.Commands.TOGGLE_COMMENT.id,
label: 'Comment/Uncomment',
order: '0'
});
}
registerKeybindings(registry: KeybindingRegistry): void {
registry.registerKeybinding({
command: ToggleComment.Commands.TOGGLE_COMMENT.id,
keybinding: 'CtrlCmd+L'
});
}
async toggleComment(): Promise<void> {
return this.run('editor.action.commentLine');
}
}
export namespace ToggleComment {
export namespace Commands {
export const TOGGLE_COMMENT: Command = {
id: 'arduino-toggle-comment'
};
}
}