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

Commit

Permalink
Opt-Space no longer scrolls (Chrome OSX)
Browse files Browse the repository at this point in the history
Summary:`Option + Space` no longer causes scrolling. This was only happening in Chrome/OSX. This was happening in the keyDown handler not the keyPress handler.

I'm not sure if I like adding the ' ' to the editor in editOnKeyDown. Maybe I should implement this as a command?

Fixes #19
Closes #244

Reviewed By: spicyj

Differential Revision: D3132586

fb-gh-sync-id: b94bd73094a58ce9b39528df34b899ae62366761
fbshipit-source-id: b94bd73094a58ce9b39528df34b899ae62366761
  • Loading branch information
brookslyrette authored and Facebook Github Bot 7 committed Apr 6, 2016
1 parent 75908ad commit 358dc59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/component/handlers/edit/editOnKeyDown.js
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,25 @@ 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 nbsp 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
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

0 comments on commit 358dc59

Please sign in to comment.