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

Opt-Space no longer scrolls (Chrome OSX) #244

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/component/handlers/edit/editOnKeyDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

'use strict';

var DraftModifier = require('DraftModifier');
var EditorState = require('EditorState');
var KeyBindingUtil = require('KeyBindingUtil');
var Keys = require('Keys');
var SecondaryClipboard = require('SecondaryClipboard');
var UserAgent = require('UserAgent');

var keyCommandBackspaceToStartOfLine = require('keyCommandBackspaceToStartOfLine');
var keyCommandBackspaceWord = require('keyCommandBackspaceWord');
Expand All @@ -29,6 +32,9 @@ var keyCommandUndo = require('keyCommandUndo');

import type {DraftEditorCommand} from 'DraftEditorCommand';

var { isOptionKeyCommand } = KeyBindingUtil;
var isChrome = UserAgent.isBrowser('Chrome');

/**
* Map a `DraftEditorCommand` command value to a corresponding function.
*/
Expand Down Expand Up @@ -101,6 +107,19 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void {
case Keys.DOWN:
this.props.onDownArrow && this.props.onDownArrow(e);
return;
case Keys.SPACE:
// handling for OSX where option + space scrolls
if (isChrome && isOptionKeyCommand(e)) {
e.preventDefault();
// insert a space into the editor
const contentState = DraftModifier.replaceText(
editorState.getCurrentContent(),
editorState.getSelection(),
'\u00a0'
);
this.update(EditorState.push(editorState, contentState, 'insert-characters'));
return;
}
}

var command = this.props.keyBindingFn(e);
Expand Down
4 changes: 4 additions & 0 deletions src/component/utils/KeyBindingUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var KeyBindingUtil = {
return !!e.ctrlKey && !e.altKey;
},

isOptionKeyCommand: function(e: SyntheticKeyboardEvent): boolean {
return isOSX && e.altKey;
},

hasCommandModifier: function(e: SyntheticKeyboardEvent): boolean {
return isOSX ?
(!!e.metaKey && !e.altKey) :
Expand Down