mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 22:45:18 +02:00
This commit is contained in:
committed by
Ian Storm Taylor
parent
aafdc4a224
commit
979dadf2d6
@@ -478,6 +478,7 @@ function Plugin(options = {}) {
|
||||
|
||||
switch (data.key) {
|
||||
case 'enter': return onKeyDownEnter(e, data, state)
|
||||
case 'space': return onKeyDownSpace(e, data, state)
|
||||
case 'backspace': return onKeyDownBackspace(e, data, state)
|
||||
case 'delete': return onKeyDownDelete(e, data, state)
|
||||
case 'left': return onKeyDownLeft(e, data, state)
|
||||
@@ -522,6 +523,27 @@ function Plugin(options = {}) {
|
||||
.apply()
|
||||
}
|
||||
|
||||
/**
|
||||
* On `Space` key down, prevent the default browser behavior
|
||||
* in Chrome, since in some situation it will result in loss of text.
|
||||
* Reference: https://github.com/ianstormtaylor/slate/issues/938
|
||||
*
|
||||
* @param {Event} e
|
||||
* @param {Object} data
|
||||
* @param {State} state
|
||||
* @return {State|Null}
|
||||
*/
|
||||
|
||||
function onKeyDownSpace(e, data, state) {
|
||||
if (IS_CHROME) {
|
||||
e.preventDefault()
|
||||
return state
|
||||
.transform()
|
||||
.insertText(' ')
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On `backspace` key down, delete backwards.
|
||||
*
|
||||
|
Reference in New Issue
Block a user