fix search for a couple of edge cases

This commit is contained in:
Fabian Jakobs 2010-04-28 16:41:17 +02:00
commit a62062e576
2 changed files with 49 additions and 6 deletions

View file

@ -140,8 +140,14 @@ ace.Search.SELECTION = 2;
var line = getLine(row);
startIndex = start.column;
var stop = false;
while (!callback(line, startIndex, row)) {
if (stop) {
return;
}
row++;
startIndex = 0;
@ -155,7 +161,7 @@ ace.Search.SELECTION = 2;
}
if (row == start.row)
return;
stop = true;
var line = getLine(row);
}
@ -181,9 +187,13 @@ ace.Search.SELECTION = 2;
var line = doc.getLine(row).substring(0, start.column);
var startIndex = 0;
var stop = false;
while (!callback(line, startIndex, row)) {
if (stop)
return;
row--;
var startIndex = 0;
@ -191,16 +201,19 @@ ace.Search.SELECTION = 2;
if (wrap) {
row = lastRow;
} else {
return null;
return;
}
}
if (row == start.row)
return null;
stop = true;
line = doc.getLine(row);
if (searchSelection && row == firstRow) {
startIndex = firstColumn;
if (searchSelection) {
if (row == firstRow)
startIndex = firstColumn;
else if (row == lastRow)
line = line.substring(0, range.end.column);
}
}
}

View file

@ -26,7 +26,6 @@ var SearchTest = new TestCase("SearchTest", {
});
var range = search.find(doc);
console.log(range)
assertPosition(1, 5, range.start);
assertPosition(1, 12, range.end);
},
@ -173,5 +172,36 @@ var SearchTest = new TestCase("SearchTest", {
doc.getSelection().selectTo(1, 2);
assertEquals(null, search.find(doc));
},
"test: edge case - match directly before the cursor" : function() {
var doc = new ace.Document(["123", "123", "juhu"]);
var search = new ace.Search().set({
needle: "juhu",
wrap: true
});
doc.getSelection().moveCursorTo(2, 5);
var range = search.find(doc);
assertPosition(2, 0, range.start);
assertPosition(2, 4, range.end);
},
"test: edge case - match backwards directly after the cursor" : function() {
var doc = new ace.Document(["123", "123", "juhu"]);
var search = new ace.Search().set({
needle: "juhu",
wrap: true,
backwards: true
});
doc.getSelection().moveCursorTo(2, 0);
var range = search.find(doc);
assertPosition(2, 0, range.start);
assertPosition(2, 4, range.end);
}
});