From 1656e98f8a5e93e96187ec3baa68925d05fe1824 Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Mon, 28 Mar 2016 21:26:25 -0400 Subject: [PATCH 1/6] Option + space no longer scrolls. --- src/component/handlers/edit/editOnKeyDown.js | 16 ++++++++++++++++ src/component/utils/KeyBindingUtil.js | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index f3f40ed405..87f4f089c4 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -12,7 +12,9 @@ 'use strict'; +var DraftModifier = require('DraftModifier'); var EditorState = require('EditorState'); +var KeyBindingUtil = require('KeyBindingUtil') var Keys = require('Keys'); var SecondaryClipboard = require('SecondaryClipboard'); @@ -29,6 +31,8 @@ var keyCommandUndo = require('keyCommandUndo'); import type {DraftEditorCommand} from 'DraftEditorCommand'; +var { isOptionKeyCommand } = KeyBindingUtil; + /** * Map a `DraftEditorCommand` command value to a corresponding function. */ @@ -101,6 +105,18 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void { case Keys.DOWN: this.props.onDownArrow && this.props.onDownArrow(e); return; + case Keys.SPACE: + if (isOptionKeyCommand(e)) { + e.preventDefault(); + // insert a space into the editor + const contentState = DraftModifier.replaceText( + editorState.getCurrentContent(), + editorState.getSelection(), + ' ' + ); + this.update(EditorState.push(editorState, contentState, 'space')); + return; + } } var command = this.props.keyBindingFn(e); diff --git a/src/component/utils/KeyBindingUtil.js b/src/component/utils/KeyBindingUtil.js index 09e60a0b73..09ad8a7a72 100644 --- a/src/component/utils/KeyBindingUtil.js +++ b/src/component/utils/KeyBindingUtil.js @@ -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) : From 12d5cd437c5a760b48d1285aeb995bcd10520709 Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Mon, 28 Mar 2016 21:26:46 -0400 Subject: [PATCH 2/6] Option + space no longer scrolls. --- src/component/handlers/edit/editOnKeyDown.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index 87f4f089c4..abcaccad4b 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -106,6 +106,7 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void { this.props.onDownArrow && this.props.onDownArrow(e); return; case Keys.SPACE: + // handling for OSX where option + space scrolls if (isOptionKeyCommand(e)) { e.preventDefault(); // insert a space into the editor From 6761bce179315db544f02f2a132dd0e5cb5b1cbb Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Mon, 28 Mar 2016 21:31:59 -0400 Subject: [PATCH 3/6] Added missing semi --- src/component/handlers/edit/editOnKeyDown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index abcaccad4b..c51fe014ad 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -14,7 +14,7 @@ var DraftModifier = require('DraftModifier'); var EditorState = require('EditorState'); -var KeyBindingUtil = require('KeyBindingUtil') +var KeyBindingUtil = require('KeyBindingUtil'); var Keys = require('Keys'); var SecondaryClipboard = require('SecondaryClipboard'); From 7c081fe5591042c9193cd2c5d7e36cf00d0061e8 Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Mon, 28 Mar 2016 21:40:01 -0400 Subject: [PATCH 4/6] Limiting this to only Chrome. --- src/component/handlers/edit/editOnKeyDown.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index c51fe014ad..bbeee5c743 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -17,6 +17,7 @@ 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'); @@ -32,6 +33,7 @@ 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. @@ -107,7 +109,7 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void { return; case Keys.SPACE: // handling for OSX where option + space scrolls - if (isOptionKeyCommand(e)) { + if (isChrome && isOptionKeyCommand(e)) { e.preventDefault(); // insert a space into the editor const contentState = DraftModifier.replaceText( From 5ab24f409e54a082b1db317edeb14f5705dd8e84 Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Tue, 29 Mar 2016 20:07:37 -0400 Subject: [PATCH 5/6] Updated to use correct EditorChangeType and corrected spacing --- src/component/handlers/edit/editOnKeyDown.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index bbeee5c743..ed69af8fc1 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -113,11 +113,11 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void { e.preventDefault(); // insert a space into the editor const contentState = DraftModifier.replaceText( - editorState.getCurrentContent(), - editorState.getSelection(), - ' ' + editorState.getCurrentContent(), + editorState.getSelection(), + ' ' ); - this.update(EditorState.push(editorState, contentState, 'space')); + this.update(EditorState.push(editorState, contentState, 'insert-characters')); return; } } From 171be7e2fb91a7a7ece2c97bb579808878e2adb5 Mon Sep 17 00:00:00 2001 From: Brooks Lyrette Date: Thu, 31 Mar 2016 18:47:14 -0400 Subject: [PATCH 6/6] Corrected inserted character to \u00a0 (non-breaking space) --- src/component/handlers/edit/editOnKeyDown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index ed69af8fc1..3b22c09215 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -115,7 +115,7 @@ function editOnKeyDown(e: SyntheticKeyboardEvent): void { const contentState = DraftModifier.replaceText( editorState.getCurrentContent(), editorState.getSelection(), - ' ' + '\u00a0' ); this.update(EditorState.push(editorState, contentState, 'insert-characters')); return;