mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 17:09:53 +02:00
fix universal matching mode for marks (#3230)
* fix universal matching mode for marks * fix lint
This commit is contained in:
@@ -345,7 +345,7 @@ export const LocationQueries = {
|
||||
|
||||
const universalMarks: Mark[] = []
|
||||
const distinctMarks: Mark[] = []
|
||||
let universalEntries: MarkEntry[] = []
|
||||
const universalEntries: MarkEntry[] = []
|
||||
let first = true
|
||||
|
||||
for (const entry of Editor.texts(editor, { reverse, at })) {
|
||||
@@ -353,8 +353,16 @@ export const LocationQueries = {
|
||||
|
||||
if (mode === 'universal') {
|
||||
if (first) {
|
||||
universalMarks.push(...node.marks)
|
||||
universalEntries = node.marks.map((m, i) => [m, i, node, path])
|
||||
for (let i = 0; i < node.marks.length; i++) {
|
||||
const mark = node.marks[i]
|
||||
const markEntry: MarkEntry = [mark, i, node, path]
|
||||
|
||||
if (match == null || Editor.isMarkMatch(editor, markEntry, match)) {
|
||||
universalMarks.push(mark)
|
||||
universalEntries.push(markEntry)
|
||||
}
|
||||
}
|
||||
|
||||
first = false
|
||||
continue
|
||||
}
|
||||
@@ -370,6 +378,7 @@ export const LocationQueries = {
|
||||
|
||||
if (!Mark.exists(existing, node.marks)) {
|
||||
universalMarks.splice(i, 1)
|
||||
universalEntries.splice(i, 1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<mark key="a">
|
||||
o<anchor />
|
||||
ne
|
||||
</mark>
|
||||
</block>
|
||||
<block>
|
||||
<mark key="a">
|
||||
<mark key="b">
|
||||
t<focus />
|
||||
wo
|
||||
</mark>
|
||||
</mark>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const run = editor => {
|
||||
return Array.from(Editor.marks(editor, { mode: 'universal' }), ([m]) => m)
|
||||
}
|
||||
|
||||
export const output = [{ key: 'a' }]
|
@@ -0,0 +1,26 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<mark key="a">
|
||||
<mark key="b">
|
||||
o<cursor />
|
||||
ne
|
||||
</mark>
|
||||
</mark>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const run = editor => {
|
||||
return Array.from(
|
||||
Editor.marks(editor, { match: { key: 'a' }, mode: 'universal' }),
|
||||
([m]) => m
|
||||
)
|
||||
}
|
||||
|
||||
export const output = [{ key: 'a' }]
|
@@ -57,8 +57,8 @@ const withMarks = editor => {
|
||||
}
|
||||
|
||||
const isMarkActive = (editor, type) => {
|
||||
const [mark] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||
return !!mark
|
||||
const [match] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||
return !!match
|
||||
}
|
||||
|
||||
const Mark = ({ attributes, children, mark }) => {
|
||||
|
@@ -100,8 +100,8 @@ const withRichText = editor => {
|
||||
}
|
||||
|
||||
const isMarkActive = (editor, type) => {
|
||||
const [mark] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||
return !!mark
|
||||
const [match] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||
return !!match
|
||||
}
|
||||
|
||||
const isBlockActive = (editor, type) => {
|
||||
|
Reference in New Issue
Block a user