search across marks

This commit is contained in:
Chrissi2812 2019-05-28 13:52:13 +02:00
parent 753fc76324
commit 331ba1c36b
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA

View File

@ -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,
})
} }
}) })
} }