mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 19:22:35 +02:00
fix arrow keys during composing, fix composing in empty blocks
This commit is contained in:
@@ -58,6 +58,7 @@ class Content extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.tmp = {}
|
this.tmp = {}
|
||||||
|
this.forces = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,12 +153,16 @@ class Content extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On composition end, remove the `isComposing` flag on the next tick.
|
* On composition end, remove the `isComposing` flag on the next tick. Also
|
||||||
|
* increment the `forces` key, which will force the contenteditable element
|
||||||
|
* to completely re-render, since IME puts React in an unreconcilable state.
|
||||||
*
|
*
|
||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onCompositionEnd = (e) => {
|
onCompositionEnd = (e) => {
|
||||||
|
this.forces++
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.tmp.isComposing = false
|
this.tmp.isComposing = false
|
||||||
})
|
})
|
||||||
@@ -254,15 +259,16 @@ class Content extends React.Component {
|
|||||||
|
|
||||||
onKeyDown = (e) => {
|
onKeyDown = (e) => {
|
||||||
if (this.props.readOnly) return
|
if (this.props.readOnly) return
|
||||||
|
const key = keycode(e.which)
|
||||||
|
|
||||||
// When composing, we don't want keydown events that are meant to end the
|
if (
|
||||||
// composition to affect the editor state.
|
this.tmp.isComposing &&
|
||||||
if (this.tmp.isComposing) {
|
key == 'left' || key == 'right' || key == 'up' || key == 'down'
|
||||||
|
) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = keycode(e.which)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(key == 'enter') ||
|
(key == 'enter') ||
|
||||||
@@ -402,6 +408,7 @@ class Content extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
key={`slate-content-${this.forces}`}
|
||||||
className={className}
|
className={className}
|
||||||
contentEditable={!readOnly}
|
contentEditable={!readOnly}
|
||||||
suppressContentEditableWarning
|
suppressContentEditableWarning
|
||||||
|
Reference in New Issue
Block a user