mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
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:
parent
a42d0113e0
commit
016ea8f86b
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user