Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Closed
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
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