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

Commit

Permalink
Allow Option+Space to be handled on OSX Chrome (#1254)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
colinjeanne authored and facebook-github-bot committed Oct 10, 2018
1 parent 8ad59c4 commit 022bcf7
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/component/handlers/edit/editOnKeyDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,29 @@ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void {
}
break;
case Keys.SPACE:
// Handling for OSX where option + space scrolls.
// Prevent Chrome on OSX behavior where option + space scrolls.
if (isChrome && isOptionKeyCommand(e)) {
e.preventDefault();
// Insert a nbsp into the editor.
const contentState = DraftModifier.replaceText(
editorState.getCurrentContent(),
editorState.getSelection(),
'\u00a0',
);
editor.update(
EditorState.push(editorState, contentState, 'insert-characters'),
);
return;
}
}

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

// If no command is specified, allow keydown event to continue.
if (!command) {
if (keyCode === Keys.SPACE && isChrome && isOptionKeyCommand(e)) {
// The default keydown event has already been prevented in order to stop
// Chrome from scrolling. Insert a nbsp into the editor as OSX would for
// other browsers.
const contentState = DraftModifier.replaceText(
editorState.getCurrentContent(),
editorState.getSelection(),
'\u00a0',
);
editor.update(
EditorState.push(editorState, contentState, 'insert-characters'),
);
}
return;
}

Expand Down

0 comments on commit 022bcf7

Please sign in to comment.