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 universalMarks: Mark[] = []
|
||||||
const distinctMarks: Mark[] = []
|
const distinctMarks: Mark[] = []
|
||||||
let universalEntries: MarkEntry[] = []
|
const universalEntries: MarkEntry[] = []
|
||||||
let first = true
|
let first = true
|
||||||
|
|
||||||
for (const entry of Editor.texts(editor, { reverse, at })) {
|
for (const entry of Editor.texts(editor, { reverse, at })) {
|
||||||
@@ -353,8 +353,16 @@ export const LocationQueries = {
|
|||||||
|
|
||||||
if (mode === 'universal') {
|
if (mode === 'universal') {
|
||||||
if (first) {
|
if (first) {
|
||||||
universalMarks.push(...node.marks)
|
for (let i = 0; i < node.marks.length; i++) {
|
||||||
universalEntries = node.marks.map((m, i) => [m, i, node, path])
|
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
|
first = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -370,6 +378,7 @@ export const LocationQueries = {
|
|||||||
|
|
||||||
if (!Mark.exists(existing, node.marks)) {
|
if (!Mark.exists(existing, node.marks)) {
|
||||||
universalMarks.splice(i, 1)
|
universalMarks.splice(i, 1)
|
||||||
|
universalEntries.splice(i, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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 isMarkActive = (editor, type) => {
|
||||||
const [mark] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
const [match] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||||
return !!mark
|
return !!match
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mark = ({ attributes, children, mark }) => {
|
const Mark = ({ attributes, children, mark }) => {
|
||||||
|
@@ -100,8 +100,8 @@ const withRichText = editor => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isMarkActive = (editor, type) => {
|
const isMarkActive = (editor, type) => {
|
||||||
const [mark] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
const [match] = Editor.marks(editor, { match: { type }, mode: 'universal' })
|
||||||
return !!mark
|
return !!match
|
||||||
}
|
}
|
||||||
|
|
||||||
const isBlockActive = (editor, type) => {
|
const isBlockActive = (editor, type) => {
|
||||||
|
Reference in New Issue
Block a user