fix decoration not updating if searching and doc changes

This commit is contained in:
Chrissi2812 2019-05-29 11:05:18 +02:00
parent 036d853378
commit 87995cb93c
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA

View File

@ -99,17 +99,16 @@ export default class Search extends Extension {
} }
find(searchTerm) { find(searchTerm) {
return ({ doc, tr }, dispatch) => { return ({ tr }, dispatch) => {
this.options.searching = true this.options.searching = true
this.searchTerm = searchTerm this.searchTerm = searchTerm
this._search(doc)
dispatch(tr) dispatch(tr)
} }
} }
createDeco(doc) { createDeco(doc) {
this._search(doc)
return this.decorations ? DecorationSet.create(doc, this.decorations) : [] return this.decorations ? DecorationSet.create(doc, this.decorations) : []
} }
@ -117,7 +116,7 @@ export default class Search extends Extension {
return [ return [
new Plugin({ new Plugin({
state: { state: {
init: (_, { doc }) => this.createDeco(doc), init() { return DecorationSet.empty },
apply: (tr, old) => { apply: (tr, old) => {
if (this.options.searching) { if (this.options.searching) {
return this.createDeco(tr.doc) return this.createDeco(tr.doc)