UX: Only do plain text table detection in outside code if HTML pasting enabled

UX: Only do plain text table detection in outside code if HTML pasting enabled

Co-authored-by: Tim Lange tim.lange@titanhq.de PR: FIX: Only do plain text table detection if outside code by venarius · Pull Request #7436 · discourse/discourse · GitHub

diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 2b82d2e..302a545 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -802,15 +802,6 @@ export default Ember.Component.extend({
     let html = clipboard.getData("text/html");
     let handled = false;
 
-    if (plainText) {
-      plainText = plainText.trim().replace(/\r/g, "");
-      const table = this._extractTable(plainText);
-      if (table) {
-        this.appEvents.trigger("composer:insert-text", table);
-        handled = true;
-      }
-    }
-
     const { pre, lineVal } = this._getSelected(null, { lineVal: true });
     const isInlinePasting = pre.match(/[^\n]$/);
 
@@ -823,6 +814,15 @@ export default Ember.Component.extend({
         );
       } else {
         canPasteHtml = !isInside(pre, /(^|\n)`‍``/g);
+
+        if (canPasteHtml) {
+          plainText = plainText.trim().replace(/\r/g, "");
+          const table = this._extractTable(plainText);
+          if (table) {
+            this.appEvents.trigger("composer:insert-text", table);
+            handled = true;
+          }
+        }
       }
     }

GitHub sha: dc2ee78f

@vinothkannans The PR had a test and it looks like it wasn’t included in this commit.

It’s not a proper test case for this change. AFAIK we don’t have a way to check the “pasting” action (like tim mentioned in PR).

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: