Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support inline nodes with content in @tiptap/suggestion #2648

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/suggestion/src/findSuggestionMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm')

const isTopLevelNode = $position.depth <= 0
const textFrom = isTopLevelNode
? 0
: $position.before()
const textTo = $position.pos
const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
const text = $position.nodeBefore?.isText && $position.nodeBefore.text

if (!text) {
return null
}

const textFrom = $position.pos - text.length
const match = Array.from(text.matchAll(regexp)).pop()

if (!match || match.input === undefined || match.index === undefined) {
Expand All @@ -53,7 +54,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
}

// The absolute position of the match in the document
const from = match.index + $position.start()
const from = textFrom + match.index
let to = from + match[0].length

// Edge case handling; if spaces are allowed and we're directly in between
Expand Down