mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-06 02:17:49 +08:00
search across marks
This commit is contained in:
parent
753fc76324
commit
331ba1c36b
@ -55,6 +55,8 @@ export default class Search extends Extension {
|
|||||||
|
|
||||||
_search(doc) {
|
_search(doc) {
|
||||||
this.results = []
|
this.results = []
|
||||||
|
const mergedTextNodes = []
|
||||||
|
let index = 0
|
||||||
|
|
||||||
if (!this.searchTerm) {
|
if (!this.searchTerm) {
|
||||||
return
|
return
|
||||||
@ -64,13 +66,29 @@ export default class Search extends Extension {
|
|||||||
|
|
||||||
doc.descendants((node, pos) => {
|
doc.descendants((node, pos) => {
|
||||||
if (node.isText) {
|
if (node.isText) {
|
||||||
let m
|
if (mergedTextNodes[index]) {
|
||||||
while (m = search.exec(node.text)) {
|
mergedTextNodes[index] = {
|
||||||
this.results.push({
|
text: mergedTextNodes[index].text + node.text,
|
||||||
from: pos + m.index,
|
pos: mergedTextNodes[index].pos,
|
||||||
to: pos + m.index + m[0].length,
|
}
|
||||||
})
|
} else {
|
||||||
|
mergedTextNodes[index] = {
|
||||||
|
text: node.text,
|
||||||
|
pos,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
mergedTextNodes.forEach(({ text, pos }) => {
|
||||||
|
let m
|
||||||
|
while (m = search.exec(text)) {
|
||||||
|
this.results.push({
|
||||||
|
from: pos + m.index,
|
||||||
|
to: pos + m.index + m[0].length,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user