1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

fix universal matching mode for marks (#3230)

* fix universal matching mode for marks

* fix lint
This commit is contained in:
Ian Storm Taylor
2019-12-04 12:57:15 -05:00
committed by GitHub
parent fe2cebb58f
commit 6627ba4b94
7 changed files with 71 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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' }]

View File

@@ -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' }]

View File

@@ -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 }) => {

View File

@@ -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) => {