Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 022bcf7

Browse files
colinjeannefacebook-github-bot
authored andcommitted
Allow Option+Space to be handled on OSX Chrome (#1254)
Summary: **Summary** Currently pressing Option+Space in Chrome on OSX will cause a nonbreaking space to always be inserted into the editor. This behavior ignores any key bindings that the editor has set. This change moves the logic which adds the non breaking space to after the point that the key binding function has been run in order to give editors a chance to handle this behavior on their own. **Test Plan** This has been tested manually since there are no current tests for the event handlers and no current framework for testing the handlers. We have been running [with this change in our fork of Draft](textioHQ@f4c3aeb) for about seven months without issue. Pull Request resolved: #1254 Differential Revision: D10241854 fbshipit-source-id: b8fe92a4f76bbb7543efdb3e5deca1dbdbc0960c
1 parent 8ad59c4 commit 022bcf7

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/component/handlers/edit/editOnKeyDown.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,29 @@ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void {
148148
}
149149
break;
150150
case Keys.SPACE:
151-
// Handling for OSX where option + space scrolls.
151+
// Prevent Chrome on OSX behavior where option + space scrolls.
152152
if (isChrome && isOptionKeyCommand(e)) {
153153
e.preventDefault();
154-
// Insert a nbsp into the editor.
155-
const contentState = DraftModifier.replaceText(
156-
editorState.getCurrentContent(),
157-
editorState.getSelection(),
158-
'\u00a0',
159-
);
160-
editor.update(
161-
EditorState.push(editorState, contentState, 'insert-characters'),
162-
);
163-
return;
164154
}
165155
}
166156

167157
const command = editor.props.keyBindingFn(e);
168158

169159
// If no command is specified, allow keydown event to continue.
170160
if (!command) {
161+
if (keyCode === Keys.SPACE && isChrome && isOptionKeyCommand(e)) {
162+
// The default keydown event has already been prevented in order to stop
163+
// Chrome from scrolling. Insert a nbsp into the editor as OSX would for
164+
// other browsers.
165+
const contentState = DraftModifier.replaceText(
166+
editorState.getCurrentContent(),
167+
editorState.getSelection(),
168+
'\u00a0',
169+
);
170+
editor.update(
171+
EditorState.push(editorState, contentState, 'insert-characters'),
172+
);
173+
}
171174
return;
172175
}
173176

0 commit comments

Comments
 (0)