Closed pfraces closed 11 years ago
Editor commands are simple static tasks but they can be easily invoked through key bindings so we must use them for as much functionality as we can and use shell commands just where parametrization is needed (like when opening a file, where a filename is needed)
Shell commands need access to the codemirror instance.
We could simply define shell commands where codemirror is defined and access to it through parent scope, but it does not allow for command modularization
Another approarch is to pass the codemirror instance to a required module which define commands. In the future, as we need to manage several codemirror instances, a more dynamic approarch will be needed, but in the meanwhile I think is a good one to go with
A task module constructor receives the dependencies needed and returns a commands object, which is a collection of named functions which receive a codemirror instance as unique argument
module.exports = function (keymap, shell, panel) {
return {
'shell.toggle': function (cm) {
...
}
};
};
A command module constructor receives a codemirror instance and returns a task object, which is a collection of named Josh command objects
module.exports = function (cm) {
return {
'file.open': {
exec: function (cmd, args, callback) {
...
},
complete: function (cmd, arg, line, callback) {
}
}
};
};
As they offer different functionallity