From db7b7eed9df1713a39cd6bde304cae077ce4c19c Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Wed, 3 Feb 2021 18:06:16 +0300 Subject: [PATCH] FIX: Restore support for pasting multiple PM recipients (#11945) This is a regression from https://github.com/discourse/discourse/commit/98201ecc24d5e5c262f1292f416dc6dd11f82d3e. Meta topic: https://meta.discourse.org/t/-/178167?u=osama. Signed-off-by: OsamaSayegh --- .../email-group-user-chooser-filter.js | 35 +++++++++++++++++++ .../components/email-group-user-chooser.js | 1 + 2 files changed, 36 insertions(+) create mode 100644 app/assets/javascripts/select-kit/addon/components/email-group-user-chooser-filter.js diff --git a/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser-filter.js b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser-filter.js new file mode 100644 index 00000000000..7b301f75d0a --- /dev/null +++ b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser-filter.js @@ -0,0 +1,35 @@ +import MultiSelectFilterComponent from "select-kit/components/multi-select/multi-select-filter"; + +export default MultiSelectFilterComponent.extend({ + classNames: ["email-group-user-chooser-filter"], + + actions: { + onPaste(event) { + const data = event.originalEvent.clipboardData; + + if (!data) { + return; + } + + const recipients = []; + data + .getData("text") + .split(/[, \n]+/) + .forEach((recipient) => { + recipient = recipient.replace(/^@+/, "").trim(); + if (recipient.length > 0) { + recipients.push(recipient); + } + }); + + if (recipients.length > 0) { + event.stopPropagation(); + event.preventDefault(); + + this.selectKit.append(recipients); + + return false; + } + }, + }, +}); diff --git a/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js index 03a940c4fd1..f7c07e516a1 100644 --- a/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js +++ b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js @@ -12,6 +12,7 @@ export default UserChooserComponent.extend({ selectKitOptions: { headerComponent: "email-group-user-chooser-header", + filterComponent: "email-group-user-chooser-filter", autoWrap: false, },