Merge branch 'main' into feature/add-moby-dick
This commit is contained in:
@@ -30,19 +30,21 @@ export default function isMarkActive(
|
|||||||
const markRanges: MarkRange[] = []
|
const markRanges: MarkRange[] = []
|
||||||
|
|
||||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||||
if (node.isText || node.marks.length) {
|
if (!node.marks.length) {
|
||||||
const relativeFrom = Math.max(from, pos)
|
return
|
||||||
const relativeTo = Math.min(to, pos + node.nodeSize)
|
|
||||||
const range = relativeTo - relativeFrom
|
|
||||||
|
|
||||||
selectionRange += range
|
|
||||||
|
|
||||||
markRanges.push(...node.marks.map(mark => ({
|
|
||||||
mark,
|
|
||||||
from: relativeFrom,
|
|
||||||
to: relativeTo,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relativeFrom = Math.max(from, pos)
|
||||||
|
const relativeTo = Math.min(to, pos + node.nodeSize)
|
||||||
|
const range = relativeTo - relativeFrom
|
||||||
|
|
||||||
|
selectionRange += range
|
||||||
|
|
||||||
|
markRanges.push(...node.marks.map(mark => ({
|
||||||
|
mark,
|
||||||
|
from: relativeFrom,
|
||||||
|
to: relativeTo,
|
||||||
|
})))
|
||||||
})
|
})
|
||||||
|
|
||||||
if (selectionRange === 0) {
|
if (selectionRange === 0) {
|
||||||
@@ -59,11 +61,7 @@ export default function isMarkActive(
|
|||||||
return type.name === markRange.mark.type.name
|
return type.name === markRange.mark.type.name
|
||||||
})
|
})
|
||||||
.filter(markRange => objectIncludes(markRange.mark.attrs, attributes, { strict: false }))
|
.filter(markRange => objectIncludes(markRange.mark.attrs, attributes, { strict: false }))
|
||||||
.reduce((sum, markRange) => {
|
.reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)
|
||||||
const size = markRange.to - markRange.from
|
|
||||||
|
|
||||||
return sum + size
|
|
||||||
}, 0)
|
|
||||||
|
|
||||||
// calculate range of marks that excludes the searched mark
|
// calculate range of marks that excludes the searched mark
|
||||||
// for example `code` doesn’t allow any other marks
|
// for example `code` doesn’t allow any other marks
|
||||||
@@ -76,11 +74,7 @@ export default function isMarkActive(
|
|||||||
return markRange.mark.type !== type
|
return markRange.mark.type !== type
|
||||||
&& markRange.mark.type.excludes(type)
|
&& markRange.mark.type.excludes(type)
|
||||||
})
|
})
|
||||||
.reduce((sum, markRange) => {
|
.reduce((sum, markRange) => sum + markRange.to - markRange.from, 0)
|
||||||
const size = markRange.to - markRange.from
|
|
||||||
|
|
||||||
return sum + size
|
|
||||||
}, 0)
|
|
||||||
|
|
||||||
// we only include the result of `excludedRange`
|
// we only include the result of `excludedRange`
|
||||||
// if there is a match at all
|
// if there is a match at all
|
||||||
|
|||||||
@@ -17,33 +17,22 @@ export default function isNodeActive(
|
|||||||
const nodeRanges: NodeRange[] = []
|
const nodeRanges: NodeRange[] = []
|
||||||
|
|
||||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||||
if (!node.isText) {
|
if (node.isText) {
|
||||||
const relativeFrom = Math.max(from, pos)
|
return
|
||||||
const relativeTo = Math.min(to, pos + node.nodeSize)
|
|
||||||
|
|
||||||
nodeRanges.push({
|
|
||||||
node,
|
|
||||||
from: relativeFrom,
|
|
||||||
to: relativeTo,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relativeFrom = Math.max(from, pos)
|
||||||
|
const relativeTo = Math.min(to, pos + node.nodeSize)
|
||||||
|
|
||||||
|
nodeRanges.push({
|
||||||
|
node,
|
||||||
|
from: relativeFrom,
|
||||||
|
to: relativeTo,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (empty) {
|
|
||||||
return !!nodeRanges
|
|
||||||
.filter(nodeRange => {
|
|
||||||
if (!type) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return type.name === nodeRange.node.type.name
|
|
||||||
})
|
|
||||||
.find(nodeRange => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }))
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectionRange = to - from
|
const selectionRange = to - from
|
||||||
|
const matchedNodeRanges = nodeRanges
|
||||||
const range = nodeRanges
|
|
||||||
.filter(nodeRange => {
|
.filter(nodeRange => {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return true
|
return true
|
||||||
@@ -52,10 +41,13 @@ export default function isNodeActive(
|
|||||||
return type.name === nodeRange.node.type.name
|
return type.name === nodeRange.node.type.name
|
||||||
})
|
})
|
||||||
.filter(nodeRange => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }))
|
.filter(nodeRange => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }))
|
||||||
.reduce((sum, nodeRange) => {
|
|
||||||
const size = nodeRange.to - nodeRange.from
|
if (empty) {
|
||||||
return sum + size
|
return !!matchedNodeRanges.length
|
||||||
}, 0)
|
}
|
||||||
|
|
||||||
|
const range = matchedNodeRanges
|
||||||
|
.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0)
|
||||||
|
|
||||||
return range >= selectionRange
|
return range >= selectionRange
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user