Select Komodo Edit 中两个书签之间的文本

Select text between two bookmarks in Komodo Edit

假设我在 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。我想知道是否有一种简单的方法 select 书签之间的所有文本,这样 combined.js 可以通过将 school.inc.js 的内容粘贴到它上面而无需使用来轻松更新组合实用程序。

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

您需要使用 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();