|
32 | 32 | for (var line = start.line, ch = start.ch, last = doc.lastLine(); line <= last; line++, ch = 0) { |
33 | 33 | regexp.lastIndex = ch |
34 | 34 | var string = doc.getLine(line), match = regexp.exec(string) |
35 | | - if (match && match[0].length) |
| 35 | + if (match) |
36 | 36 | return {from: Pos(line, match.index), |
37 | 37 | to: Pos(line, match.index + match[0].length), |
38 | 38 | match: match} |
|
57 | 57 | chunk = chunk * 2 |
58 | 58 | regexp.lastIndex = start.ch |
59 | 59 | var match = regexp.exec(string) |
60 | | - if (match && match[0].length) { |
| 60 | + if (match) { |
61 | 61 | var before = string.slice(0, match.index).split("\n"), inside = match[0].split("\n") |
62 | 62 | var startLine = start.line + before.length - 1, startCh = before[before.length - 1].length |
63 | 63 | return {from: Pos(startLine, startCh), |
|
86 | 86 | var string = doc.getLine(line) |
87 | 87 | if (ch > -1) string = string.slice(0, ch) |
88 | 88 | var match = lastMatchIn(string, regexp) |
89 | | - if (match && match[0].length) |
| 89 | + if (match) |
90 | 90 | return {from: Pos(line, match.index), |
91 | 91 | to: Pos(line, match.index + match[0].length), |
92 | 92 | match: match} |
|
104 | 104 | chunk *= 2 |
105 | 105 |
|
106 | 106 | var match = lastMatchIn(string, regexp) |
107 | | - if (match && match[0].length) { |
| 107 | + if (match) { |
108 | 108 | var before = string.slice(0, match.index).split("\n"), inside = match[0].split("\n") |
109 | 109 | var startLine = line + before.length, startCh = before[before.length - 1].length |
110 | 110 | return {from: Pos(startLine, startCh), |
|
223 | 223 |
|
224 | 224 | find: function(reverse) { |
225 | 225 | var result = this.matches(reverse, this.doc.clipPos(reverse ? this.pos.from : this.pos.to)) |
| 226 | + |
| 227 | + // Implements weird auto-growing behavior on null-matches for |
| 228 | + // backwards-compatiblity with the vim code (unfortunately) |
| 229 | + while (result && CodeMirror.cmpPos(result.from, result.to) == 0) { |
| 230 | + if (reverse) { |
| 231 | + if (result.from.ch) result.from = Pos(result.from.line, result.from.ch - 1) |
| 232 | + else if (result.from.line == this.doc.firstLine()) result = null |
| 233 | + else result = this.matches(reverse, this.doc.clipPos(Pos(result.from.line - 1))) |
| 234 | + } else { |
| 235 | + if (result.to.ch < this.doc.getLine(result.to.line).length) result.to = Pos(result.to.line, result.to.ch + 1) |
| 236 | + else if (result.to.line == this.doc.lastLine()) result = null |
| 237 | + else result = this.matches(reverse, Pos(result.to.line + 1, 0)) |
| 238 | + } |
| 239 | + } |
| 240 | + |
226 | 241 | if (result) { |
227 | 242 | this.pos = result |
228 | 243 | this.atOccurrence = true |
|
0 commit comments