首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Komodo编辑中在两个书签之间选择文本

在Komodo编辑中在两个书签之间选择文本
EN

Stack Overflow用户
提问于 2016-01-12 18:24:06
回答 1查看 95关注 0票数 0

假设我在combined.js中有以下(示例)代码

代码语言:javascript
复制
/* 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 9.3.x中被书签标记为// inline comments标记的位置。

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-12 22:36:15

没有内置的方式来完成这个任务,但是您可以通过编写Userscript来完成它。

您将需要使用Komodo编辑器SDK

代码语言:javascript
复制
// 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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34751137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档