use internal variable for commands to determine if search should update

Prior to this if search was closed (searching: false) the commands won't do anything.
This commit is contained in:
Chrissi2812 2019-05-29 12:46:36 +02:00
parent a42d0113e0
commit 016ea8f86b
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA

View File

@ -8,6 +8,7 @@ export default class Search extends Extension {
this.results = []
this.searchTerm = null
this._updating = false
}
get name() {
@ -104,22 +105,27 @@ export default class Search extends Extension {
}
find(searchTerm) {
return ({ tr }, dispatch) => {
this.options.searching = true
return (state, dispatch) => {
this.searchTerm = (this.options.disableRegex) ? searchTerm.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') : searchTerm
dispatch(tr)
this.updateView(state, dispatch)
}
}
clear() {
return ({ tr }, dispatch) => {
return (state, dispatch) => {
this.searchTerm = null
dispatch(tr)
this.updateView(state, dispatch)
}
}
updateView({ tr }, dispatch) {
this._updating = true
dispatch(tr)
this._updating = false
}
createDeco(doc) {
this._search(doc)
return this.decorations ? DecorationSet.create(doc, this.decorations) : []
@ -131,7 +137,9 @@ export default class Search extends Extension {
state: {
init() { return DecorationSet.empty },
apply: (tr, old) => {
if (this.options.searching || (tr.docChanged && this.options.alwaysSearch)) {
if (this._updating
|| this.options.searching
|| (tr.docChanged && this.options.alwaysSearch)) {
return this.createDeco(tr.doc)
}
if (tr.docChanged) {