| orion.edit.command | ||
|---|---|---|
|
|
|
| Plugging into the editor | orion.edit.contentAssist | |
The orion.edit.command service is the simplest kind of editor extension. An editor command simply provides a function that takes some editor text as input, performs some operation or transformation on the text, and returns a new text value. The command can also optionally receive and return selection information for changing the editor selection.
Implementations of orion.edit.command must define the following function:
Implementations of orion.edit.command may define the following attributes:
String Optional. A tooltip describing the command.
The following simple example just converts the selected text to upper case. In this example the function return value is a simple string, so this is interpreted by the editor as replacement for the original editor selection. In the service properties, we see the command provides a key binding of Ctrl+U (or Cmd+U on Mac).
var provider = new eclipse.PluginProvider();
provider.registerServiceProvider("orion.edit.command", {
run : function(text) {
return text.toUpperCase();
}
}, {
name : "UPPERCASE",
img : "/images/gear.gif",
key : [ "u", true ]
});
provider.connect();
Here is an example of a slightly more complex run function that takes the selection and wraps it in C-style block comments. In this example the function returns a complex object with both text and selection fields. These are interpreted by the editor as the new editor buffer contents, and the new editor selection. A content type is used so that this command is only available for javascript files.
contentType: ["application/javascript"],
run : function(selectedText, text, selection) {
return {text: text.substring(0,selection.start) + "/*" +
text.substring(selection.start,selection.end) + "*/" +
text.substring(selection.end),
selection: {start:selection.start,end:selection.end+4}};
}
|
|
|
| Plugging into the editor | orion.edit.contentAssist |