Skip to content

Commit

Permalink
fix node walking
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Sep 27, 2023
1 parent f5e793d commit 4b47380
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/view/com/composer/text-input/web/TagDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@

import {Mark} from '@tiptap/core'
import {Plugin, PluginKey} from '@tiptap/pm/state'
import {findChildren} from '@tiptap/core'
import {Node as ProsemirrorNode} from '@tiptap/pm/model'
import {Decoration, DecorationSet} from '@tiptap/pm/view'

function getDecorations(doc: ProsemirrorNode) {
const decorations: Decoration[] = []

findChildren(doc, node => node.type.name === 'paragraph').forEach(
paragraphNode => {
const textContent = paragraphNode.node.textContent
doc.descendants((node, pos) => {
if (node.isText && node.text) {
const regex = /(?:^|\s)(#[^\d\s]\S*)(?=\s)?/g
const textContent = node.textContent

let match
while ((match = regex.exec(textContent))) {
const [m] = match
const hasLeadingSpace = /^\s/.test(m)
const tag = m.trim().replace(/\p{P}+$/gu, '')
const [matchedString, tag] = match

if (tag.length > 66) continue
const from = match.index + (hasLeadingSpace ? 2 : 1)
const to = from + tag.length + 1

const from = match.index + matchedString.indexOf(tag)
const to = from + tag.length

decorations.push(
Decoration.inline(paragraphNode.pos + from, paragraphNode.pos + to, {
Decoration.inline(pos + from, pos + to, {
class: 'autolink',
}),
)
}
},
)
}
})

return DecorationSet.create(doc, decorations)
}
Expand Down

0 comments on commit 4b47380

Please sign in to comment.