(replaceValue: string, opt = { isSingle: true, isRegexp: false })
| 79 | } |
| 80 | |
| 81 | replace(replaceValue: string, opt = { isSingle: true, isRegexp: false }) { |
| 82 | const { isSingle, isRegexp, ...rest } = opt; |
| 83 | const options = Object.assign({}, DEFAULT_SEARCH_OPTIONS, rest); |
| 84 | const { matches, value, index } = this; |
| 85 | |
| 86 | if (matches.length) { |
| 87 | if (isRegexp) |
| 88 | replaceValue = buildRegexValue(matches[index], replaceValue); |
| 89 | |
| 90 | if (isSingle) { |
| 91 | // replace one |
| 92 | this._innerReplace([matches[index]], replaceValue); |
| 93 | } |
| 94 | else { |
| 95 | // replace all |
| 96 | this._innerReplace(matches, replaceValue); |
| 97 | } |
| 98 | const highlightIndex = index < matches.length - 1 ? index : index - 1; |
| 99 | |
| 100 | this.search(value, { |
| 101 | ...options, |
| 102 | highlightIndex: isSingle ? highlightIndex : -1, |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | return this; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Find preview or next value, and highlight it. |
no test coverage detected