Skip to content

Commit

Permalink
fix: Check code mark presence instead of any mark in `canInsertSugg…
Browse files Browse the repository at this point in the history
…estion` (#791)
  • Loading branch information
rfgamaral committed May 13, 2024
1 parent cf7451f commit 2f70959
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/utilities/can-insert-suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ function canInsertSuggestion({ editor, state }: { editor: Editor; state: EditorS
const isInsideCodeBlockNode = selection.$from.parent.type.name === 'codeBlock'

const wordsBeforeSelection = (selection.$from.nodeBefore?.text ?? '').split(' ')
const nodeBeforeSelection = selection.$from.parent.cut(
selection.$from.parentOffset - wordsBeforeSelection.slice(-1)[0].length - 1,
selection.$from.parentOffset - 1,
).content.firstChild

const hasCodeMarkBefore =
(selection.$from.parent.cut(
selection.$from.parentOffset - wordsBeforeSelection.slice(-1)[0].length - 1,
selection.$from.parentOffset - 1,
).content.firstChild?.marks.length ?? 0) > 0
const hasCodeMarkBefore = (nodeBeforeSelection?.marks ?? []).some(
(mark) => mark.type.name === 'code',
)

const isComposingInlineCode = wordsBeforeSelection.some((word) => word.startsWith('`'))

Expand Down

0 comments on commit 2f70959

Please sign in to comment.