ActiveState Powered by ActiveState

ActiveState Community


Trigger - now with tabstop support!

Posted by jeffg on 2007-08-15 10:49
OS: All / Any

Based on a suggestion from Nat[1] I updated Trigger with some code to detect tabstops in the snippet and emulate hitting tab the first time:

try {
var view = ko.views.manager.currentView;
view.setFocus();
view.scimoz.wordLeftExtend();

var name = ko.interpolate.interpolateStrings('%s');
var snippet = ko.projects.findPart('snippet', name, 'container');

if(snippet) {
    Snippet_insert(snippet);
    var rx = /(«|\%tabstop\:)/g;
    if (rx.test(snippet.value)) {
        ko.commands.doCommand('cmd_indent');
    }
} else {
    var msg = "no snippet found named " + snippet;
    StatusBar_AddMessage(msg,"debugger",5000,true);
}
} catch(e) {
    alert(e);
}

try {
var view = ko.views.manager.currentView;
view.setFocus();
view.scimoz.wordLeftExtend();

var name = ko.interpolate.interpolateStrings('%s');
var snippet = ko.projects.findPart('snippet', name, 'container');

if(snippet) {
    Snippet_insert(snippet);
    var rx = /(«|\%tabstop\:)/g;
    if (rx.test(snippet.value)) {
        ko.commands.doCommand('cmd_indent');
    }
} else {
    var msg = "no snippet found named " + snippet;
    StatusBar_AddMessage(msg,"debugger",5000,true);
}
} catch(e) {
    alert(e);
}

[1] http://community.activestate.com/forum-topic/snippets-problem-tabstops#c...

Update: I corrected the code above to handle all tabstops, not just the older style ones I originally tested with =)

Update: I updated the above snippet with re-written code that only uses the new ko.* api. This version of trigger wil only work with 4.2.0 Beta 7 and later.

AttachmentSize
trigger-tabstops.kpz1.23 KB
trigger-ko42.kpz1.23 KB
-->