文書から検索

提供: MeryWiki
移動先: 案内検索

現在開いているすべての文書から文字列を検索します。

// -----------------------------------------------------------------------------
// 文書から検索
//
// Copyright (c) Kuro. All Rights Reserved.
// www:    http://www.haijin-boys.com/
// -----------------------------------------------------------------------------
 
var s = prompt("検索", "");
if (s == "")
    Quit();
 
editor.NewFile();
var d = editor.ActiveDocument;
var r = new RegExp(s, "i");
for (var e = new Enumerator(editor.documents); !e.atEnd(); e.moveNext()) {
  var item = e.item();
  if (item != d)
    d.selection.Text = Find(item, r);
}
with (d.selection) {
    StartOfDocument();
    Find(s, meFindNext + meFindReplaceRegExp);
    StartOfDocument();
}
 
function Find(d, r) {
    var s1 = d.Text.split("\n");
    var s2  = new Array();
    var s3 = "";
    for (var i = 0; i < s1.length; i++) {
        var s3 = r.exec(s1[i]);
        if (s3)
            s2.push((d.FullName != "" ? d.FullName : "無題") + "(" + (i + 1) + "): " + s1[i]);
    }
    s3 = s2.join("\n");
    return s3 != "" ? (s3 + "\n") : "";
}