|
2283 | 2283 | var regexPart = argString.substring(slashes[0] + 1, slashes[1]); |
2284 | 2284 | var replacePart = ''; |
2285 | 2285 | var flagsPart; |
| 2286 | + var count; |
2286 | 2287 | if (slashes[1]) { |
2287 | 2288 | replacePart = argString.substring(slashes[1] + 1, slashes[2]); |
2288 | 2289 | } |
2289 | 2290 | if (slashes[2]) { |
2290 | | - flagsPart = argString.substring(slashes[2] + 1); |
| 2291 | + // After the 3rd slash, we can have flags followed by a space followed |
| 2292 | + // by count. |
| 2293 | + var trailing = argString.substring(slashes[2] + 1).split(' '); |
| 2294 | + flagsPart = trailing[0]; |
| 2295 | + count = parseInt(trailing[1]); |
2291 | 2296 | } |
2292 | 2297 | if (flagsPart) { |
2293 | 2298 | regexPart = regexPart + '/' + flagsPart; |
2294 | 2299 | } |
2295 | | - updateSearchQuery(cm, regexPart, true /** ignoreCase */, |
| 2300 | + if (regexPart) { |
| 2301 | + // If regex part is empty, then use the previous query. Otherwise use |
| 2302 | + // the regex part as the new query. |
| 2303 | + updateSearchQuery(cm, regexPart, true /** ignoreCase */, |
2296 | 2304 | true /** smartCase */); |
| 2305 | + } |
2297 | 2306 | var state = getSearchState(cm); |
2298 | 2307 | var query = state.getQuery(); |
2299 | | - var startPos = clipCursorToContent(cm, { line: params.line || 0, |
2300 | | - ch: 0 }); |
| 2308 | + var lineStart = params.line || 0; |
| 2309 | + var lineEnd = params.lineEnd || lineStart; |
| 2310 | + if (count) { |
| 2311 | + lineStart = lineEnd; |
| 2312 | + lineEnd = lineStart + count - 1; |
| 2313 | + } |
| 2314 | + var startPos = clipCursorToContent(cm, { line: lineStart, ch: 0 }); |
2301 | 2315 | function doReplace() { |
2302 | 2316 | for (var cursor = cm.getSearchCursor(query, startPos); |
2303 | | - cursor.findNext();) { |
2304 | | - if (!isInRange(cursor.from(), params.line, params.lineEnd)) { |
2305 | | - break; |
2306 | | - } |
| 2317 | + cursor.findNext() && |
| 2318 | + isInRange(cursor.from(), lineStart, lineEnd);) { |
2307 | 2319 | var text = cm.getRange(cursor.from(), cursor.to()); |
2308 | 2320 | var newText = text.replace(query, replacePart); |
2309 | 2321 | cursor.replace(newText); |
|
0 commit comments