Skip to content

Commit

Permalink
fix: check for excluded marks in isMarkActive, fix #1388
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed May 29, 2021
1 parent a66db3e commit 3c4cc96
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/core/src/helpers/isMarkActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default function isMarkActive(
return false
}

const range = markRanges
// calculate range of matched mark
const matchedRange = markRanges
.filter(markRange => {
if (!type) {
return true
Expand All @@ -60,8 +61,32 @@ export default function isMarkActive(
.filter(markRange => objectIncludes(markRange.mark.attrs, attributes))
.reduce((sum, markRange) => {
const size = markRange.to - markRange.from

return sum + size
}, 0)

// calculate range of marks that excludes the searched mark
// for example `code` doesn’t allow any other marks
const excludedRange = markRanges
.filter(markRange => {
if (!type) {
return true
}

return markRange.mark.type !== type
&& markRange.mark.type.excludes(type)
})
.reduce((sum, markRange) => {
const size = markRange.to - markRange.from

return sum + size
}, 0)

// we only include the result of `excludedRange`
// if there is a match at all
const range = matchedRange > 0
? matchedRange + excludedRange
: matchedRange

return range >= selectionRange
}

0 comments on commit 3c4cc96

Please sign in to comment.