orion.edit.model

An orion.edit.model service provides listeners on changes made to the orion.textview.TextView that powers the Orion editor.

Service methods

An implementation of orion.edit.model may define zero or more functions depending on what event types it wants to receive. When an event of type X is dispatched by the TextView, this the implementation's service method named onX will be invoked, passing the the event. For example, when the TextView dispatches a "ModelChanged" event, the provider's "onModelChanged()" method is invoked and passed the ModelChanged event object.

The methods are always invoked with a single parameter, event, containing the event data that was dispatched by the TextView. The return value is ignored.

The current list of supported "onX" methods is as follows:

Consult the TextView Client API reference for details about these event types.

Service attributes

Implementations of orion.edit.model must define the following attributes:

contentType
String[] An array of Content Type IDs that this provider wants to receive events for. The provider will only be notified of events that occur when the file being edited matches (or descends from) a content type given in the array.

Example 1

The following example prints out some information to the browser console when certain text events occur while a JavaScript file is being edited.

var provider = new orion.PluginProvider();
provider.registerService("orion.edit.model", 
    {
        onModelChanging: function(event) {
            console.log("Text is about to be inserted: " + event.text);
        },
        onScroll: function(event) {
            console.log("Editor scrolled to " + event.newValue.x + ", " + event.newValue.y);
        }
    },
    {
        contentType: [ "application/javascript" ]
    }});
provider.connect();

Example 2

See the source code of the orion-codemirror plugin, which uses onModelChanging to build a shadow copy of the Orion text buffer, which it then uses to perform syntax highlighting.