From db0429da1f0212d1244eb99fb832023644b3a76f Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Fri, 27 Aug 2021 11:56:46 -0500 Subject: [PATCH] DEV: make composer-upload-uppy more flexible --- .../discourse/app/components/composer-editor-uppy.js | 2 ++ .../discourse/app/mixins/composer-upload-uppy.js | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/composer-editor-uppy.js b/app/assets/javascripts/discourse/app/components/composer-editor-uppy.js index 152b1fbee81..1e230a37814 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor-uppy.js +++ b/app/assets/javascripts/discourse/app/components/composer-editor-uppy.js @@ -9,4 +9,6 @@ export default ComposerEditor.extend(ComposerUploadUppy, { uploadType: "composer", uppyId: "composer-editor-uppy", composerModel: alias("composer"), + composerModelContentKey: "reply", + editorInputClass: ".d-editor-input", }); diff --git a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js index 36a82b3a1c7..885c86b3f9b 100644 --- a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js +++ b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js @@ -334,9 +334,9 @@ export default Mixin.create({ filename: escapedFilename + "(?:\\()?([0-9])?(?:\\))?", })}\\]\\(\\)`; const globalRegex = new RegExp(regexString, "g"); - const matchingPlaceholder = this.get("composerModel.reply").match( - globalRegex - ); + const matchingPlaceholder = this.get( + `composerModel.${this.composerModelContentKey}` + ).match(globalRegex); if (matchingPlaceholder) { // get last matching placeholder and its consecutive nr in regex // capturing group and apply +1 to the placeholder @@ -525,7 +525,7 @@ export default Mixin.create({ _bindPasteListener() { this.pasteEventListener = function pasteListener(event) { if ( - document.activeElement !== document.querySelector(".d-editor-input") + document.activeElement !== document.querySelector(this.editorInputClass) ) { return; }