Read-only search tabs, cb() from openFile, bug fix
Making search results stop exactly on limit
This commit is contained in:
parent
3f9d7116bd
commit
2418b6f049
4 changed files with 42 additions and 28 deletions
|
@ -12,6 +12,7 @@ define([
|
|||
|
||||
var raiseTab = function(tab) {
|
||||
editor.setSession(tab);
|
||||
editor.setReadOnly(tab.readOnly);
|
||||
command.fire("session:syntax");
|
||||
command.fire("session:render");
|
||||
editor.focus();
|
||||
|
|
|
@ -42,7 +42,7 @@ define([
|
|||
});
|
||||
|
||||
this.animationClass = "enter";
|
||||
|
||||
this.readOnly = false;
|
||||
};
|
||||
|
||||
//hopefully this never screws up unaugmented Ace sessions.
|
||||
|
|
|
@ -344,7 +344,7 @@ define([
|
|||
});
|
||||
},
|
||||
|
||||
openFile: function(path) {
|
||||
openFile: function(path, c) {
|
||||
var self = this;
|
||||
var found = false;
|
||||
var node = this.pathMap[path];
|
||||
|
@ -370,10 +370,18 @@ define([
|
|||
},
|
||||
//if no match found, create a tab
|
||||
function() {
|
||||
if (found) return;
|
||||
if (found) {
|
||||
if (c) {
|
||||
c();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var file = new File(node.entry);
|
||||
file.read(function(err, data) {
|
||||
sessions.addFile(data, file);
|
||||
if (c) {
|
||||
c();
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -75,8 +75,7 @@ define([
|
|||
var isCaseSensitive = this.element.find("#search-case-check").checked;
|
||||
var displayQuery = this.input.value;
|
||||
|
||||
var resultsTab = sessions.addFile(i18n.get("searchDisplayQuery", displayQuery));
|
||||
resultsTab.file = new NullFile();
|
||||
var resultsTab = this.createResultsTab(displayQuery);
|
||||
|
||||
this.currentSearch = {
|
||||
matches: 0,
|
||||
|
@ -85,11 +84,6 @@ define([
|
|||
resultsTab: resultsTab
|
||||
};
|
||||
|
||||
resultsTab.fileName = i18n.get("searchTabName", displayQuery);
|
||||
resultsTab.addEventListener("close", function() {
|
||||
self.currentSearch.running = false;
|
||||
});
|
||||
|
||||
var fileEntryList = this.getFlatFileEntryList();
|
||||
if (fileEntryList.length < 1) { // exit early if there are no directories added
|
||||
self.appendToResults(i18n.get("searchNoDirectories"));
|
||||
|
@ -145,19 +139,25 @@ define([
|
|||
var options = this.currentSearch;
|
||||
|
||||
chrome.fileSystem.getDisplayPath(nodeEntry, function(path) {
|
||||
var file = new File(nodeEntry);
|
||||
if (!options.running) {
|
||||
return c();
|
||||
}
|
||||
|
||||
var printResult = function(index, str) {
|
||||
self.appendToResults(self.formatResultCode(index, str));
|
||||
};
|
||||
var file = new File(nodeEntry);
|
||||
|
||||
file.read(function(err, data) {
|
||||
if (!options.running) {
|
||||
return c();
|
||||
}
|
||||
|
||||
var lines = data.split("\n");
|
||||
var firstFindInFile = true;
|
||||
var printedLines = {}; // only print each line once per file per search
|
||||
var printResult = function(index, str) {
|
||||
printedLines[index] = true;
|
||||
var result = " " + (index + 1) + ": " + str;
|
||||
self.appendToResults(result);
|
||||
};
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
line = lines[i];
|
||||
|
@ -170,25 +170,23 @@ define([
|
|||
}
|
||||
|
||||
if (firstFindInFile) { // only add a filename if it is the first result for the file
|
||||
self.appendToResults("\n" + nodeEntry.fullPath + "\n");
|
||||
self.appendToResults(""); // add an extra blank line
|
||||
self.appendToResults(nodeEntry.fullPath);
|
||||
firstFindInFile = false;
|
||||
} else if (!printedLines[i] && !printedLines[i-1] && !printedLines[i-2]) { // add break if immediately previous lines not included
|
||||
self.appendToResults("...\n");
|
||||
self.appendToResults("...");
|
||||
}
|
||||
|
||||
if (!printedLines[i-1] && i > 1) { // don't print line number 0
|
||||
printResult(i-1, lines[i-1]);
|
||||
printedLines[i-1] = true;
|
||||
}
|
||||
|
||||
if (!printedLines[i]) {
|
||||
printResult(i, lines[i]);
|
||||
printedLines[i] = true;
|
||||
}
|
||||
|
||||
if (i < lines.length - 1) { // always print the line following the search result, if it exists
|
||||
printResult(i+1, lines[i+1]);
|
||||
printedLines[i+1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +196,21 @@ define([
|
|||
});
|
||||
},
|
||||
|
||||
createResultsTab: function(displayQuery) {
|
||||
var self = this;
|
||||
|
||||
var resultsTab = sessions.addFile(i18n.get("searchDisplayQuery", displayQuery));
|
||||
resultsTab.file = new NullFile();
|
||||
resultsTab.fileName = i18n.get("searchTabName", displayQuery);
|
||||
resultsTab.addEventListener("close", function() {
|
||||
self.currentSearch.running = false;
|
||||
});
|
||||
resultsTab.readOnly = true;
|
||||
editor.setReadOnly(true);
|
||||
|
||||
return resultsTab;
|
||||
},
|
||||
|
||||
printSearchSummary: function(searchedEverything, filesScanned) {
|
||||
this.appendToResults(i18n.get("searchSummary", this.currentSearch.matches, filesScanned));
|
||||
if (!searchedEverything) {
|
||||
|
@ -206,18 +219,10 @@ define([
|
|||
this.currentSearch.running = false;
|
||||
},
|
||||
|
||||
formatResultCode: function(lineNumber, code) {
|
||||
return " " + (lineNumber + 1) + ": " + code + "\n";
|
||||
},
|
||||
|
||||
appendToResults: function(text) {
|
||||
if (text === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
var resultsTab = this.currentSearch.resultsTab;
|
||||
var insertRow = resultsTab.doc.getLength();
|
||||
resultsTab.doc.insert({row: insertRow, column: 0}, text);
|
||||
resultsTab.doc.insert({row: insertRow, column: 0}, text + "\n");
|
||||
resultsTab.modified = false;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue