mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 18:39:51 +02:00
Show example of a workaround for Chrome bug that puts cursor in wrong place (#4772)
There is a Chromium bug where, if you have an inline at the end of a block, clicking the end of a block puts the cursor inside the inline instead of inside the final {text: ''} node. This commit updates the inlines example to show the problem, and to show a known workaround for the problem. See for context: https://github.com/ianstormtaylor/slate/issues/4704
This commit is contained in:
@@ -47,8 +47,16 @@ const initialValue: Descendant[] = [
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
text:
|
text:
|
||||||
'There are two ways to add links. You can either add a link via the toolbar icon above, or if you want in on a little secret, copy a URL to your keyboard and paste it while a range of text is selected.',
|
'There are two ways to add links. You can either add a link via the toolbar icon above, or if you want in on a little secret, copy a URL to your keyboard and paste it while a range of text is selected. ',
|
||||||
},
|
},
|
||||||
|
// The following is an example of an inline at the end of a block.
|
||||||
|
// This is an edge case that can cause issues.
|
||||||
|
{
|
||||||
|
type: 'link',
|
||||||
|
url: 'https://twitter.com/JustMissEmma/status/1448679899531726852',
|
||||||
|
children: [{ text: 'Finally, here is our favorite dog video.' }],
|
||||||
|
},
|
||||||
|
{ text: '' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -96,6 +104,7 @@ const InlinesExample = () => {
|
|||||||
</Toolbar>
|
</Toolbar>
|
||||||
<Editable
|
<Editable
|
||||||
renderElement={props => <Element {...props} />}
|
renderElement={props => <Element {...props} />}
|
||||||
|
renderLeaf={props => <Text {...props} />}
|
||||||
placeholder="Enter some text..."
|
placeholder="Enter some text..."
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
/>
|
/>
|
||||||
@@ -291,6 +300,29 @@ const Element = props => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Text = props => {
|
||||||
|
const { attributes, children, leaf } = props
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
// The following is a workaround for a Chromium bug where,
|
||||||
|
// if you have an inline at the end of a block,
|
||||||
|
// clicking the end of a block puts the cursor inside the inline
|
||||||
|
// instead of inside the final {text: ''} node
|
||||||
|
// https://github.com/ianstormtaylor/slate/issues/4704#issuecomment-1006696364
|
||||||
|
className={
|
||||||
|
leaf.text === ''
|
||||||
|
? css`
|
||||||
|
padding-left: 0.1px;
|
||||||
|
`
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
{...attributes}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const AddLinkButton = () => {
|
const AddLinkButton = () => {
|
||||||
const editor = useSlate()
|
const editor = useSlate()
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user