Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't break macOS emoji insert nor composition when fixing #938 #994

Merged
merged 3 commits into from
Aug 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/plugins/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ function Plugin(options = {}) {
// the cursor isn't technique in the right spot. (2016/12/01)
(!(pInline && !pInline.isVoid && startOffset == 0)) &&
(!(nInline && !nInline.isVoid && startOffset == startText.length)) &&
// COMPAT: When inserting a Space character, Chrome will sometimes
// split the text node into two adjacent text nodes. See:
// https://github.com/ianstormtaylor/slate/issues/938
(!(e.data === ' ' && IS_CHROME)) &&
// If the
(chars.equals(nextChars))
)
Expand Down Expand Up @@ -478,7 +482,6 @@ 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)
Expand Down Expand Up @@ -523,27 +526,6 @@ 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.
*
Expand Down