ソースを参照

ComposeArea: Don't submit text on IME selection

Refs #777
Danilo Bargen 6 年 前
コミット
c0944741b2
1 ファイル変更20 行追加0 行削除
  1. 20 0
      src/directives/compose_area.ts

+ 20 - 0
src/directives/compose_area.ts

@@ -280,6 +280,17 @@ export default [
                 }
 
                 // Handle typing events
+
+                let isComposing = false;
+
+                function onCompositionStart(ev: KeyboardEvent): void {
+                    isComposing = true;
+                }
+
+                function onCompositionEnd(ev: KeyboardEvent): void {
+                    isComposing = false;
+                }
+
                 function onKeyDown(ev: KeyboardEvent): void {
                     // If enter is pressed, prevent default event from being dispatched
                     if (!ev.shiftKey && ev.key === 'Enter') {
@@ -292,6 +303,13 @@ export default [
                         return;
                     }
 
+                    // If the enter key is part of a composition (e.g. when
+                    // entering text with an IME), don't submit the text.
+                    // See https://github.com/threema-ch/threema-web/issues/777
+                    if ((ev as any).isComposing || isComposing) {
+                        return;
+                    }
+
                     // At link time, the element is not yet evaluated.
                     // Therefore add following code to end of event loop.
                     $timeout(() => {
@@ -621,6 +639,8 @@ export default [
                 }
 
                 // Handle typing events
+                composeDiv.on('compositionstart', onCompositionStart);
+                composeDiv.on('compositionend', onCompositionEnd);
                 composeDiv.on('keydown', onKeyDown);
                 composeDiv.on('keyup', onKeyUp);