pfraces-graveyard / wed

web editor
0 stars 0 forks source link

define shell and editor commands in different ways #13

Closed pfraces closed 11 years ago

pfraces commented 11 years ago

As they offer different functionallity

pfraces commented 11 years ago

Where to define what

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)

pfraces commented 11 years ago

Shell commands definition

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

pfraces commented 11 years ago

Spec

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) {
            }
        }
    };
};