Ver código fonte

Use getText instead of innerHtml (#382)

Fixes an issue with the compose area being cleared when entering an emoji and then a space.
Silly 8 anos atrás
pai
commit
c7b8bec178
1 arquivos alterados com 5 adições e 4 exclusões
  1. 5 4
      src/directives/compose_area.ts

+ 5 - 4
src/directives/compose_area.ts

@@ -145,7 +145,7 @@ export default [
                 }
 
                 // Process a DOM node recursively and extract text from compose area.
-                function getText() {
+                function getText(trim = true) {
                     let text = '';
                     const visitChildNodes = (parentNode: HTMLElement) => {
                         // tslint:disable-next-line: prefer-for-of (see #98)
@@ -174,7 +174,7 @@ export default [
                         }
                     };
                     visitChildNodes(composeDiv[0]);
-                    return text.trim();
+                    return trim ? text.trim() : text;
                 }
 
                 // Determine whether field is empty
@@ -275,7 +275,8 @@ export default [
                     $timeout(() => {
                         // If the compose area contains only a single <br>, make it fully empty.
                         // See also: https://stackoverflow.com/q/14638887/284318
-                        if (composeDiv[0].innerText === '\n') {
+                        let text = getText(false);
+                        if (text === '\n') {
                             composeDiv[0].innerText = '';
                         }
 
@@ -285,7 +286,7 @@ export default [
                         } else {
                             startTyping();
                         }
-                        scope.onTyping(getText());
+                        scope.onTyping(text.trim());
 
                         updateView();
                     }, 0);