1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +02:00

Fixes #938 chrome eating first line of text on space at beginning of line (#991)

This commit is contained in:
Dan Burzo
2017-08-15 20:42:33 +03:00
committed by Ian Storm Taylor
parent aafdc4a224
commit 979dadf2d6

View File

@@ -478,6 +478,7 @@ function Plugin(options = {}) {
switch (data.key) { switch (data.key) {
case 'enter': return onKeyDownEnter(e, data, state) case 'enter': return onKeyDownEnter(e, data, state)
case 'space': return onKeyDownSpace(e, data, state)
case 'backspace': return onKeyDownBackspace(e, data, state) case 'backspace': return onKeyDownBackspace(e, data, state)
case 'delete': return onKeyDownDelete(e, data, state) case 'delete': return onKeyDownDelete(e, data, state)
case 'left': return onKeyDownLeft(e, data, state) case 'left': return onKeyDownLeft(e, data, state)
@@ -522,6 +523,27 @@ function Plugin(options = {}) {
.apply() .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. * On `backspace` key down, delete backwards.
* *