search again after replace, fix edge case

This commit is contained in:
Philipp Kühn
2019-06-04 22:35:06 +02:00
parent 1b071e5035
commit 5c9948a330

View File

@@ -91,9 +91,15 @@ export default class Search extends Extension {
replace(replace) {
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))
this.editor.commands.find(this.searchTerm)
}
}
@@ -119,13 +125,19 @@ export default class Search extends Extension {
replaceAll(replace) {
return ({ tr }, dispatch) => {
let offset
if (!this.results.length) {
return
}
this.results.forEach(({ from, to }, index) => {
tr.insertText(replace, from, to)
offset = this.rebaseNextResult(replace, index, offset)
})
dispatch(tr)
this.editor.commands.find(this.searchTerm)
}
}