在Komodo Edit

时间:2016-01-12 18:24:07

标签: komodo komodoedit

我们说combined.js中有以下(示例)代码:

/* jQuery, Moment.js, Bootstrap, etc. */

Child.prototype.doSchool = function(data) { // Bookmarked
    var essay = data.essay || {};

    if (essay) {
        var spelling = checkSpelling(essay, EN_US_GRADE_7);

        return spelling.grade();
    }
}

/* Extensive and Turing-complete code base */

var burt = new Child();
if (burt.doSchool({essay: "i like trains"}) < .65) burt.comfort(); // Bookmarked

/* jQuery extensions, Fallout 4, etc. */

该文件已在Komodo Edit 9.3.x中标记为// inline comments标记的位置。

任何/* block comments */表示数千行代码。

书签之间的来源存在于另一个文件school.inc.js中。我想知道是否有一种简单的方法来选择书签之间的所有文本,以便通过将combined.js的内容粘贴在其上而不必使用组合实用程序,可以轻松更新school.inc.js

1 个答案:

答案 0 :(得分:1)

没有内置方法可以做到这一点,但您可以通过编写用户脚本来实现。

您需要使用Komodo Editor SDK

// This assumes you're running the Userscript starting at the first bookmark
var editor = require("ko/editor");
var startSelect;
var endSelect;
var done = false;

function selectBookmarkRegion(){
    if(editor.bookmarkExists()) { // check if bookmark is set on current line
        startSelect = { // save it's line start
                line: editor.getLineNumber(),
                ch: 0
            }; 
    } else {
        alert("Start me on a line with a Bookmark");
    }

    editor.goLineDown();
    while(!done){
        if(editor.bookmarkExists())
        {
            endSelect = {
                line: editor.getLineNumber(),
                ch: editor.getLineSize()
            };// Save line end
            done = true;
        }
        editor.goLineDown();
        // found a bug as I was writing this.  Will be fixed in the next releases
        if (editor.getLineNumber() + 1 == editor.lineCount())
        {
            done = true;
        }
    }
    editor.setSelection(startSelect, endSelect); // Wrap the selection
}

selectBookmarkRegion();