|
40 | 40 | var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;}; |
41 | 41 | var target = query.split("\n"); |
42 | 42 | // Different methods for single-line and multi-line queries |
43 | | - if (target.length == 1) |
44 | | - this.matches = function(reverse, pos) { |
45 | | - var line = fold(cm.getLine(pos.line)), len = query.length, match; |
46 | | - if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1) |
47 | | - : (match = line.indexOf(query, pos.ch)) != -1) |
48 | | - return {from: {line: pos.line, ch: match}, |
49 | | - to: {line: pos.line, ch: match + len}}; |
50 | | - }; |
51 | | - else |
| 43 | + if (target.length == 1) { |
| 44 | + if (!query.length) { |
| 45 | + // Empty string would match anything and never progress, so |
| 46 | + // we define it to match nothing instead. |
| 47 | + this.matches = function() {}; |
| 48 | + } else { |
| 49 | + this.matches = function(reverse, pos) { |
| 50 | + var line = fold(cm.getLine(pos.line)), len = query.length, match; |
| 51 | + if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1) |
| 52 | + : (match = line.indexOf(query, pos.ch)) != -1) |
| 53 | + return {from: {line: pos.line, ch: match}, |
| 54 | + to: {line: pos.line, ch: match + len}}; |
| 55 | + }; |
| 56 | + } |
| 57 | + } else { |
52 | 58 | this.matches = function(reverse, pos) { |
53 | 59 | var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln)); |
54 | 60 | var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match)); |
|
70 | 76 | return {from: reverse ? end : start, to: reverse ? start : end}; |
71 | 77 | } |
72 | 78 | }; |
| 79 | + } |
73 | 80 | } |
74 | 81 | } |
75 | 82 |
|
|
0 commit comments