ICommandService commandService =\r
(ICommandService)textEditor.getSite().getService(ICommandService.class);\r
for(Command command: commandService.getDefinedCommands()) {\r
- if(!command.isEnabled()) {\r
- continue;\r
- }\r
- if(!command.getId().endsWith(".toggle.comment")) {\r
+ if(!isEnabledToggleCommentCommand(command)) {\r
continue;\r
}\r
+ \r
+ // if the selection is empty, the marked region will be new selection.\r
getSelection(true);\r
+ \r
IHandlerService handlerService =\r
(IHandlerService)textEditor.getSite().getService(IHandlerService.class);\r
handlerService.executeCommand(command.getId(), null);\r
- break;\r
+ return;\r
}\r
}\r
+ \r
+ private boolean isEnabledToggleCommentCommand(Command command) {\r
+ return command.isEnabled() && command.getId().endsWith(".toggle.comment");\r
+ }\r
}\r