2016-01-12 99 views
0

比方说,我有以下的(例子)代码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. */ 

该文件是在由// inline comments标记的位置科莫多编辑9.3.x书签。

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

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

回答

1

没有内置的方法来做到这一点,但你可以通过编写一个Userscript来做到这一点。

你会想要使用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(); 
+0

不错!这解决了我的问题。谢谢你的帮助! – cyberbit

+0

嘿,别担心!很高兴我能帮上忙。 – cgchoffman