mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 02:03:59 +02:00
Fix reporting of marks on a markableVoid (#5186)
Add a few unit tests for Editor.marks(), including one for markable void that fails
This commit is contained in:
5
.changeset/sixty-ghosts-invent.md
Normal file
5
.changeset/sixty-ghosts-invent.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Report marks applied to a markableVoid if selection is collapsed
|
@@ -816,6 +816,10 @@ export const Editor: EditorInterface = {
|
|||||||
|
|
||||||
if (anchor.offset === 0) {
|
if (anchor.offset === 0) {
|
||||||
const prev = Editor.previous(editor, { at: path, match: Text.isText })
|
const prev = Editor.previous(editor, { at: path, match: Text.isText })
|
||||||
|
const markedVoid = Editor.above(editor, {
|
||||||
|
match: n => Editor.isVoid(editor, n) && editor.markableVoid(n),
|
||||||
|
})
|
||||||
|
if (!markedVoid) {
|
||||||
const block = Editor.above(editor, {
|
const block = Editor.above(editor, {
|
||||||
match: n => Editor.isBlock(editor, n),
|
match: n => Editor.isBlock(editor, n),
|
||||||
})
|
})
|
||||||
@@ -829,6 +833,7 @@ export const Editor: EditorInterface = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { text, ...rest } = node
|
const { text, ...rest } = node
|
||||||
return rest
|
return rest
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
<text>word</text>
|
||||||
|
<inline void markable>
|
||||||
|
<text bold />
|
||||||
|
<cursor />
|
||||||
|
</inline>
|
||||||
|
<text />
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const test = editor => {
|
||||||
|
editor.markableVoid = node => node.markable
|
||||||
|
return Editor.marks(editor)
|
||||||
|
}
|
||||||
|
export const output = { bold: true }
|
@@ -0,0 +1,32 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
<text>word</text>
|
||||||
|
<inline void markable>
|
||||||
|
<anchor />
|
||||||
|
<text bold />
|
||||||
|
</inline>
|
||||||
|
<text bold>
|
||||||
|
<anchor />
|
||||||
|
bold
|
||||||
|
</text>
|
||||||
|
<inline void markable>
|
||||||
|
<text bold italic />
|
||||||
|
</inline>
|
||||||
|
<text bold italic>
|
||||||
|
bold italic
|
||||||
|
<focus />
|
||||||
|
</text>
|
||||||
|
<text />
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const test = editor => {
|
||||||
|
editor.markableVoid = node => node.markable
|
||||||
|
return Editor.marks(editor)
|
||||||
|
}
|
||||||
|
export const output = { bold: true }
|
24
packages/slate/test/interfaces/Editor/marks/mixed-text.tsx
Normal file
24
packages/slate/test/interfaces/Editor/marks/mixed-text.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
plain
|
||||||
|
<text bold>
|
||||||
|
<anchor />
|
||||||
|
bold
|
||||||
|
</text>
|
||||||
|
<text bold italic>
|
||||||
|
bold italic
|
||||||
|
<focus />
|
||||||
|
</text>
|
||||||
|
</block>
|
||||||
|
<block>block two</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const test = editor => {
|
||||||
|
return Editor.marks(editor)
|
||||||
|
}
|
||||||
|
export const output = { bold: true }
|
@@ -0,0 +1,24 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
plain
|
||||||
|
<text bold>
|
||||||
|
text that is
|
||||||
|
<cursor />
|
||||||
|
bold
|
||||||
|
</text>
|
||||||
|
<text bold italic>
|
||||||
|
bold italic
|
||||||
|
</text>
|
||||||
|
</block>
|
||||||
|
<block>block two</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const test = editor => {
|
||||||
|
return Editor.marks(editor)
|
||||||
|
}
|
||||||
|
export const output = { bold: true }
|
Reference in New Issue
Block a user