Merge pull request #423 from probablycorey/master
Search's FindAll has issues when cursor is in the middle of the line.
This commit is contained in:
commit
18f5ca584f
2 changed files with 40 additions and 12 deletions
|
|
@ -98,11 +98,21 @@ Search.SELECTION = 2;
|
||||||
iterator = this.$forwardMatchIterator(session);
|
iterator = this.$forwardMatchIterator(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoreCursorColumn = this.$options.wrap && this.$options.scope == Search.ALL;
|
||||||
|
var start = session.getSelection().getCursor();
|
||||||
|
if (ignoreCursorColumn) {
|
||||||
|
session.getSelection().moveCursorTo(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
var ranges = [];
|
var ranges = [];
|
||||||
iterator.forEach(function(range) {
|
iterator.forEach(function(range) {
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (ignoreCursorColumn) {
|
||||||
|
session.getSelection().moveCursorTo(start.row, start.column)
|
||||||
|
}
|
||||||
|
|
||||||
return ranges;
|
return ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,24 @@ module.exports = {
|
||||||
assert.equal(search.replace("ab12", "$$"), "$");
|
assert.equal(search.replace("ab12", "$$"), "$");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"test: find all using regular expresion containing $" : function() {
|
||||||
|
var session = new EditSession(["a", " b", "c ", "d"]);
|
||||||
|
|
||||||
|
var search = new Search().set({
|
||||||
|
needle: "[ ]+$",
|
||||||
|
regExp: true,
|
||||||
|
wrap: true,
|
||||||
|
scope: Search.ALL
|
||||||
|
});
|
||||||
|
|
||||||
|
session.getSelection().moveCursorTo(1, 2);
|
||||||
|
var ranges = search.findAll(session);
|
||||||
|
|
||||||
|
assert.equal(ranges.length, 1);
|
||||||
|
assert.position(ranges[0].start, 2, 1);
|
||||||
|
assert.position(ranges[0].end, 2, 2);
|
||||||
|
},
|
||||||
|
|
||||||
"test: find all matches in a line" : function() {
|
"test: find all matches in a line" : function() {
|
||||||
var session = new EditSession("foo bar foo baz foobar foo");
|
var session = new EditSession("foo bar foo baz foobar foo");
|
||||||
|
|
||||||
|
|
@ -362,12 +380,12 @@ module.exports = {
|
||||||
var ranges = search.findAll(session);
|
var ranges = search.findAll(session);
|
||||||
|
|
||||||
assert.equal(ranges.length, 3);
|
assert.equal(ranges.length, 3);
|
||||||
assert.position(ranges[0].start, 0, 8);
|
assert.position(ranges[0].start, 0, 0);
|
||||||
assert.position(ranges[0].end, 0, 11);
|
assert.position(ranges[0].end, 0, 3);
|
||||||
assert.position(ranges[1].start, 0, 23);
|
assert.position(ranges[1].start, 0, 8);
|
||||||
assert.position(ranges[1].end, 0, 26);
|
assert.position(ranges[1].end, 0, 11);
|
||||||
assert.position(ranges[2].start, 0, 0);
|
assert.position(ranges[2].start, 0, 23);
|
||||||
assert.position(ranges[2].end, 0, 3);
|
assert.position(ranges[2].end, 0, 26);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: find all matches in a line backwards" : function() {
|
"test: find all matches in a line backwards" : function() {
|
||||||
|
|
@ -385,12 +403,12 @@ module.exports = {
|
||||||
var ranges = search.findAll(session);
|
var ranges = search.findAll(session);
|
||||||
|
|
||||||
assert.equal(ranges.length, 3);
|
assert.equal(ranges.length, 3);
|
||||||
assert.position(ranges[0].start, 0, 8);
|
assert.position(ranges[0].start, 0, 23);
|
||||||
assert.position(ranges[0].end, 0, 11);
|
assert.position(ranges[0].end, 0, 26);
|
||||||
assert.position(ranges[1].start, 0, 0);
|
assert.position(ranges[1].start, 0, 8);
|
||||||
assert.position(ranges[1].end, 0, 3);
|
assert.position(ranges[1].end, 0, 11);
|
||||||
assert.position(ranges[2].start, 0, 23);
|
assert.position(ranges[2].start, 0, 0);
|
||||||
assert.position(ranges[2].end, 0, 26);
|
assert.position(ranges[2].end, 0, 3);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue