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