search again after replace, fix edge case
This commit is contained in:
@@ -91,9 +91,15 @@ export default class Search extends Extension {
|
|||||||
|
|
||||||
replace(replace) {
|
replace(replace) {
|
||||||
return (state, dispatch) => {
|
return (state, dispatch) => {
|
||||||
const { from, to } = this.results[0]
|
const firstResult = this.results[0]
|
||||||
|
|
||||||
|
if (!firstResult) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { from, to } = this.results[0]
|
||||||
dispatch(state.tr.insertText(replace, from, to))
|
dispatch(state.tr.insertText(replace, from, to))
|
||||||
|
this.editor.commands.find(this.searchTerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,13 +125,19 @@ export default class Search extends Extension {
|
|||||||
replaceAll(replace) {
|
replaceAll(replace) {
|
||||||
return ({ tr }, dispatch) => {
|
return ({ tr }, dispatch) => {
|
||||||
let offset
|
let offset
|
||||||
|
|
||||||
|
if (!this.results.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.results.forEach(({ from, to }, index) => {
|
this.results.forEach(({ from, to }, index) => {
|
||||||
tr.insertText(replace, from, to)
|
tr.insertText(replace, from, to)
|
||||||
|
|
||||||
offset = this.rebaseNextResult(replace, index, offset)
|
offset = this.rebaseNextResult(replace, index, offset)
|
||||||
})
|
})
|
||||||
|
|
||||||
dispatch(tr)
|
dispatch(tr)
|
||||||
|
|
||||||
|
this.editor.commands.find(this.searchTerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user