From 970ecdb7158340cec2ea9e9a381d86afa8a59430 Mon Sep 17 00:00:00 2001
From: Bob Zeleznik <zzzman@gmail.com>
Date: Tue, 26 Mar 2019 00:02:30 -0400
Subject: tried to fix keyboard event issue when editing a text note in an
 embedded free form collection.

---
 src/client/views/collections/PreviewCursor.tsx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'src/client/views/collections/PreviewCursor.tsx')

diff --git a/src/client/views/collections/PreviewCursor.tsx b/src/client/views/collections/PreviewCursor.tsx
index cbf36cf9e..5d621f321 100644
--- a/src/client/views/collections/PreviewCursor.tsx
+++ b/src/client/views/collections/PreviewCursor.tsx
@@ -37,13 +37,13 @@ export class PreviewCursor extends React.Component<PreviewCursorProps>  {
 
     @action
     cleanupInteractions = () => {
-        document.removeEventListener("keypress", this.onKeyPress, true);
+        document.removeEventListener("keypress", this.onKeyPress, false);
     }
 
     @action
     onCursorPlaced = (visible: boolean, downX: number, downY: number): void => {
         if (visible) {
-            document.addEventListener("keypress", this.onKeyPress, true);
+            document.addEventListener("keypress", this.onKeyPress, false);
             this._lastX = downX;
             this._lastY = downY;
         } else
@@ -52,8 +52,11 @@ export class PreviewCursor extends React.Component<PreviewCursorProps>  {
 
     @action
     onKeyPress = (e: KeyboardEvent) => {
+        // Mixing events between React and Native is finicky.  In FormattedTextBox, we set the
+        // DASHFormattedTextBoxHandled flag when a text box consumes a key press so that we can ignore
+        // the keyPress here.
         //if not these keys, make a textbox if preview cursor is active!
-        if (!e.ctrlKey && !e.altKey && !e.defaultPrevented) {
+        if (!e.ctrlKey && !e.altKey && !e.defaultPrevented && !(e as any).DASHFormattedTextBoxHandled) {
             //make textbox and add it to this collection
             let [x, y] = this.props.getTransform().transformPoint(this._lastX, this._lastY);
             let newBox = Documents.TextDocument({ width: 200, height: 100, x: x, y: y, title: "new" });
-- 
cgit v1.2.3-70-g09d2

