Esempio n. 1
0
 }).then(function(files) {
     var packageFiles = [];
     var packageRoot = path.split("/").slice(0, -1).join("/");
     files.forEach(function(path) {
         if (path.indexOf(packageRoot) === 0) {
             var filename = path.substring(packageRoot.length + 1);
             if (filename !== "package.json" && filename !== "config.json") {
                 packageFiles.push(filename);
             }
         }
     });
     json.files = packageFiles;
     return session.setText(path, JSON.stringify(json, null, 4));
 });
Esempio n. 2
0
File: search.js Progetto: bartaz/zed
                project.listFiles(function(err, fileList) {
                    fileList = fileList.filter(function(filename) {
                        var parts = filename.split('.');
                        var ext = parts[parts.length - 1];
                        return filterExtensions.indexOf(ext) === -1;
                    });

                    session.setText("zed::search", "Searching " + fileList.length + " files for '" + phrase + "'...\nPut your cursor on the result press Enter to jump.\n", function() {});
                    async.eachLimit(fileList, 10, function(path, next) {
                        if (results >= MAX_RESULTS) {
                            return next();
                        }

                        if (path === "/tags") {
                            return next();
                        }

                        project.readFile(path, function(err, text) {
                            if (err) {
                                console.error(path, err);
                                return next();
                            }
                            if (!stringIsText(text)) {
                                return next();
                            }
                            var matchIdx = 0;
                            while ((matchIdx = text.indexOf(phrase, matchIdx)) !== -1) {
                                append("\n" + path + ":" + indexToLine(text, matchIdx) + "\n\t" + getLine(text, matchIdx) + "\n");
                                matchIdx++;
                                results++;
                                if (results >= MAX_RESULTS) {
                                    break;
                                }
                            }
                            next();
                        });
                    }, function() {
                        if (results === 0) {
                            append("\nNo results found.");
                        } else {
                            append("\nFound " + results + " results.");
                        }
                        callback();
                    });
                });
Esempio n. 3
0
 }).then(function(packages) {
     session.setText("zed::zpm::installed", "Installed packages\n==================\n");
     append("\nCommands: [Install New]      [Update All]\n");
     var pkg;
     if (Object.keys(packages).length === 0) {
         append("\nYou do not have any packages installed.\n", function() {});
     } else {
         for (var id in packages) {
             pkg = packages[id];
             append("\n" + pkg.name + "\n");
             append("URI: " + id + "\n");
             append("Version: " + pkg.version + "\n");
             append("Description: " + pkg.description + "\n");
             append("Commands: [Uninstall]      [Update]\n");
         }
     }
     return session.setCursorPosition("zed::zpm::installed", {
         row: 0,
         column: 0
     });
 });
Esempio n. 4
0
 session.getText(path, function(err, text) {
     var sortedText = sortLines(text);
     session.setText(path, sortedText, callback);
 });
Esempio n. 5
0
 return session.getText(path).then(function(text) {
     text = text.replace('<widget id="' + info.replace + '"', '<widget id="' + info.replaceWith + '"');
     return session.setText(path, text);
 });
Esempio n. 6
0
module.exports = function(info) {
    var text = info.inputs.text;
    return session.setText(info.path, JSON5.stringify(JSON5.parse(text), null, 4));
};
Esempio n. 7
0
    }).then(function(fileList_) {
        var pathRegex = new RegExp(wildcardToRegexp(parsedPhrase.pathPattern));

        fileList = fileList_;
        fileList = fileList.filter(function(filename) {
            var parts = filename.split('.');
            var ext = parts[parts.length - 1];
            if (filterExtensions.indexOf(ext) !== -1) {
                return false;
            }
            return parsedPhrase.pathPattern ? pathRegex.exec(filename) : true;
        });
        session.setText("zed::search", "Searching " + fileList.length + " files for '" + parsedPhrase.text + "'...\nPut your cursor on the result press Enter to jump.\n");
        var filePromises = fileList.map(function(path) {
            var phraseText = parsedPhrase.text;
            if (parsedPhrase.regex) {
                var phraseRegex = new RegExp(parsedPhrase.text, "g");
            }
            if (parsedPhrase.caseInsensitive) {
                phraseText = phraseText.toLowerCase();
            }
            if (results >= MAX_RESULTS) {
                return;
            }

            if (path === "/tags" || path.indexOf("zed::") === 0) {
                return;
            }

            return fs.readFile(path).then(function(text) {
                if (!stringIsText(text)) {
                    return;
                }
                var matchIdx = 0;
                var searchText = parsedPhrase.caseInsensitive ? text.toLowerCase() : text;
                if (parsedPhrase.regex) {
                    var lines = searchText.split("\n");
                    var m;
                    for (var i = 0; i < lines.length; i++) {
                        while (m = phraseRegex.exec(lines[i])) {
                            append("\n" + path + ":" + (i + 1) + "\n\t" + lines[i] + "\n");
                            results++;
                            if (results >= MAX_RESULTS) {
                                break;
                            }
                        }
                    }
                } else {
                    while ((matchIdx = searchText.indexOf(phraseText, matchIdx)) !== -1) {
                        append("\n" + path + ":" + indexToLine(text, matchIdx) + "\n\t" + getLine(text, matchIdx) + "\n");
                        matchIdx++;
                        results++;
                        if (results >= MAX_RESULTS) {
                            break;
                        }
                    }
                }
            }, function() {
                console.error("Could not read file: " + path);
                // If a few files fail that's ok, just report
            });
        });
        return Promise.all(filePromises);
    }).then(function() {