Bug 762452 - file filtering behaves strangely; r=past

This commit is contained in:
Victor Porof 2012-06-19 18:11:27 +03:00
Родитель 3b877334d0
Коммит b98737b6f2
3 изменённых файлов: 97 добавлений и 65 удалений

Просмотреть файл

@ -136,6 +136,7 @@ RemoteDebuggerPrompt.prototype = {
function ScriptsView() {
this._onScriptsChange = this._onScriptsChange.bind(this);
this._onScriptsSearch = this._onScriptsSearch.bind(this);
this._onScriptsKeyUp = this._onScriptsKeyUp.bind(this);
}
ScriptsView.prototype = {
@ -387,6 +388,29 @@ ScriptsView.prototype = {
}
},
/**
* Gets the entered file, line and token entered in the searchbox.
*
* @return array
* A [file, line, token] array.
*/
_getSearchboxInfo: function DVS__getSearchboxInfo() {
let rawValue = this._searchbox.value.toLowerCase();
let rawLength = rawValue.length;
let lastColon = rawValue.lastIndexOf(":");
let lastAt = rawValue.lastIndexOf("#");
let fileEnd = lastColon != -1 ? lastColon : lastAt != -1 ? lastAt : rawLength;
let lineEnd = lastAt != -1 ? lastAt : rawLength;
let file = rawValue.slice(0, fileEnd);
let line = window.parseInt(rawValue.slice(fileEnd + 1, lineEnd)) || -1;
let token = rawValue.slice(lineEnd + 1);
return [file, line, token];
},
/**
* The click listener for the scripts container.
*/
@ -402,18 +426,7 @@ ScriptsView.prototype = {
_onScriptsSearch: function DVS__onScriptsSearch(e) {
let editor = DebuggerView.editor;
let scripts = this._scripts;
let rawValue = this._searchbox.value.toLowerCase();
let rawLength = rawValue.length;
let lastColon = rawValue.lastIndexOf(":");
let lastAt = rawValue.lastIndexOf("#");
let fileEnd = lastColon != -1 ? lastColon : lastAt != -1 ? lastAt : rawLength;
let lineEnd = lastAt != -1 ? lastAt : rawLength;
let file = rawValue.slice(0, fileEnd);
let line = window.parseInt(rawValue.slice(fileEnd + 1, lineEnd)) || -1;
let token = rawValue.slice(lineEnd + 1);
let [file, line, token] = this._getSearchboxInfo();
// Presume we won't find anything.
scripts.selectedItem = this._preferredScript;
@ -426,9 +439,9 @@ ScriptsView.prototype = {
} else {
for (let i = 0, l = scripts.itemCount, found = false; i < l; i++) {
let item = scripts.getItemAtIndex(i);
let target = item.value.toLowerCase();
let target = item.label.toLowerCase();
// Search is not case sensitive, and is tied to the url not the label.
// Search is not case sensitive, and is tied to the label not the url.
if (target.match(file)) {
item.hidden = false;
@ -449,8 +462,7 @@ ScriptsView.prototype = {
if (token) {
let offset = editor.find(token, { ignoreCase: true });
if (offset > -1) {
editor.setCaretPosition(0);
editor.setCaretOffset(offset);
editor.setSelection(offset, offset + token.length)
}
}
},
@ -465,11 +477,11 @@ ScriptsView.prototype = {
}
if (e.keyCode === e.DOM_VK_RETURN || e.keyCode === e.DOM_VK_ENTER) {
let token = this._getSearchboxInfo()[2];
let editor = DebuggerView.editor;
let offset = editor.findNext(true);
if (offset > -1) {
editor.setCaretPosition(0);
editor.setCaretOffset(offset);
editor.setSelection(offset, offset + token.length)
}
}
},

Просмотреть файл

@ -45,6 +45,8 @@ function test()
}
function testScriptSearching() {
var token;
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gScripts = gDebugger.DebuggerView.Scripts;
@ -56,103 +58,107 @@ function testScriptSearching() {
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
write("#debugger");
token = "debugger";
write("#" + token);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44,
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (1)");
EventUtils.sendKey("RETURN");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (2)");
EventUtils.sendKey("ENTER");
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 8,
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct token. (3)");
EventUtils.sendKey("ENTER");
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4,
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (4)");
EventUtils.sendKey("RETURN");
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44,
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (5)");
write(":bogus#debugger;");
token = "debugger;";
write(":bogus#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (6)");
write(":13#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (7)");
write(":13#debugger;");
write(":#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
"The editor didn't jump to the correct token. (7)");
write(":#debugger;");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (8)");
write("::#debugger;");
write("::#" + token.length);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (9)");
write(":::#debugger;");
write(":::#" + token.length);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (10)");
write(":i am not a number");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't remain at the correct token. (11)");
write("#__i do not exist__");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't remain at the correct token. (12)");
token = "debugger";
write(":1:2:3:a:b:c:::12");
ok(gEditor.getCaretPosition().line == 11 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line. (13)");
write("#don't#find#me#instead#find#debugger");
write("#don't#find#me#instead#find#" + token);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44,
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (14)");
EventUtils.sendKey("RETURN");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2,
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (15)");
EventUtils.sendKey("ENTER");
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 8,
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct token. (16)");
EventUtils.sendKey("RETURN");
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4,
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (17)");
EventUtils.sendKey("ENTER");
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44,
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (18)");
clear();
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44,
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't remain at the correct token. (19)");
is(gScripts.visibleItemsCount, 1,
"Not all the scripts are shown after the search. (20)");
@ -172,7 +178,7 @@ function write(text) {
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i]);
}
dump("editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {

Просмотреть файл

@ -62,15 +62,15 @@ function testScriptSearching() {
function firstSearch() {
window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
dump("Current script url:\n" + aEvent.detail.url + "\n");
dump("Debugger editor text:\n" + gEditor.getText() + "\n");
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
window.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
dump("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 4 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line. (1)");
@ -85,38 +85,52 @@ function firstSearch() {
}
function secondSearch() {
let token = "deb";
window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
dump("Current script url:\n" + aEvent.detail.url + "\n");
dump("Debugger editor text:\n" + gEditor.getText() + "\n");
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
window.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
dump("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8,
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct line. (2)");
is(gScripts.visibleItemsCount, 1,
"Not all the correct scripts are shown after the search. (2)");
finalCheck();
finalCheck(0, "ugger;", token);
});
}
});
write(".*-02\.js#debugger;");
write(".*-02\.js#" + token);
}
function finalCheck() {
clear();
function finalCheck(i, string, token) {
info("Searchbox value: " + gSearchBox.value);
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8,
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (3)");
if (string[i]) {
EventUtils.sendChar(string[i]);
finalCheck(i + 1, string, token);
return;
}
clear();
executeSoon(function() {
is(gScripts.visibleItemsCount, 2,
"Not all the scripts are shown after the search. (3)");
"Not all the scripts are shown after the searchbox was emptied.");
closeDebuggerAndFinish();
});
}
function clear() {
@ -130,7 +144,7 @@ function write(text) {
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i]);
}
dump("editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {