()
| 351 | } |
| 352 | |
| 353 | private replace() { |
| 354 | const query = this.getQuery(); |
| 355 | // Allow empty replacement (delete match) by only requiring a search term. |
| 356 | if (!query.search) return; |
| 357 | |
| 358 | const { from, to } = this.view.state.selection.main; |
| 359 | const currentText = this.view.state.sliceDoc(from, to); |
| 360 | |
| 361 | // 检查当前选中的文本是否匹配搜索词 |
| 362 | const isMatch = query.caseSensitive ? |
| 363 | currentText === query.search : |
| 364 | currentText.toLowerCase() === query.search.toLowerCase(); |
| 365 | |
| 366 | if (isMatch) { |
| 367 | this.view.dispatch({ |
| 368 | changes: { from, to, insert: query.replace }, |
| 369 | selection: { anchor: from, head: from + query.replace.length } |
| 370 | }); |
| 371 | this.findNext(); |
| 372 | } else { |
| 373 | // 如果当前选中的不匹配,先查找下一个匹配项 |
| 374 | this.findNext(); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | private replaceAll() { |
| 379 | const query = this.getQuery(); |
no test coverage detected