2016-01-12 42 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