FIX: Skip pasting files if plain text available in clipboard
This commit is contained in:
parent
dbadebacd1
commit
e2c60ea4b2
|
@ -9,6 +9,9 @@ const Discourse = Ember.Application.extend({
|
||||||
RAW_TEMPLATES: {},
|
RAW_TEMPLATES: {},
|
||||||
__widget_helpers: {},
|
__widget_helpers: {},
|
||||||
showingSignup: false,
|
showingSignup: false,
|
||||||
|
customEvents: {
|
||||||
|
paste: 'paste'
|
||||||
|
},
|
||||||
|
|
||||||
getURL(url) {
|
getURL(url) {
|
||||||
if (!url) return url;
|
if (!url) return url;
|
||||||
|
|
|
@ -13,7 +13,8 @@ import { tinyAvatar,
|
||||||
displayErrorForUpload,
|
displayErrorForUpload,
|
||||||
getUploadMarkdown,
|
getUploadMarkdown,
|
||||||
validateUploadedFiles,
|
validateUploadedFiles,
|
||||||
formatUsername
|
formatUsername,
|
||||||
|
clipboardData
|
||||||
} from 'discourse/lib/utilities';
|
} from 'discourse/lib/utilities';
|
||||||
import { cacheShortUploadUrl, resolveAllShortUrls } from 'pretty-text/image-short-url';
|
import { cacheShortUploadUrl, resolveAllShortUrls } from 'pretty-text/image-short-url';
|
||||||
|
|
||||||
|
@ -394,7 +395,14 @@ export default Ember.Component.extend({
|
||||||
pasteZone: $element,
|
pasteZone: $element,
|
||||||
});
|
});
|
||||||
|
|
||||||
$element.on('fileuploadpaste', () => this._pasted = true);
|
$element.on('fileuploadpaste', (e) => {
|
||||||
|
let {types} = clipboardData(e);
|
||||||
|
this._pasted = true;
|
||||||
|
|
||||||
|
if (types.some(t => t === "text/plain")) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$element.on('fileuploadsubmit', (e, data) => {
|
$element.on('fileuploadsubmit', (e, data) => {
|
||||||
const isPrivateMessage = this.get("composer.privateMessage");
|
const isPrivateMessage = this.get("composer.privateMessage");
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { emojiSearch, isSkinTonableEmoji } from 'pretty-text/emoji';
|
||||||
import { emojiUrlFor } from 'discourse/lib/text';
|
import { emojiUrlFor } from 'discourse/lib/text';
|
||||||
import { getRegister } from 'discourse-common/lib/get-owner';
|
import { getRegister } from 'discourse-common/lib/get-owner';
|
||||||
import { findRawTemplate } from 'discourse/lib/raw-templates';
|
import { findRawTemplate } from 'discourse/lib/raw-templates';
|
||||||
import { determinePostReplaceSelection } from 'discourse/lib/utilities';
|
import { determinePostReplaceSelection, clipboardData } from 'discourse/lib/utilities';
|
||||||
import deprecated from 'discourse-common/lib/deprecated';
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
// Our head can be a static string or a function that returns a string
|
// Our head can be a static string or a function that returns a string
|
||||||
|
@ -616,6 +616,14 @@ export default Ember.Component.extend({
|
||||||
Ember.run.scheduleOnce("afterRender", () => $textarea.focus());
|
Ember.run.scheduleOnce("afterRender", () => $textarea.focus());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
paste(e) {
|
||||||
|
let {types} = clipboardData(e);
|
||||||
|
|
||||||
|
if (types.some(t => t === "Files") && !types.some(t => t === "text/plain")) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
emojiSelected(code) {
|
emojiSelected(code) {
|
||||||
let selected = this._getSelected();
|
let selected = this._getSelected();
|
||||||
|
|
|
@ -421,5 +421,14 @@ export function isAppleDevice() {
|
||||||
!navigator.userAgent.match(/Trident/g);
|
!navigator.userAgent.match(/Trident/g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clipboardData(e) {
|
||||||
|
let data = e.clipboardData ||
|
||||||
|
e.originalEvent.clipboardData ||
|
||||||
|
e.delegatedEvent.originalEvent.clipboardData ||
|
||||||
|
event.clipboardData;
|
||||||
|
|
||||||
|
return { items: data.items, types: data.types };
|
||||||
|
}
|
||||||
|
|
||||||
// This prevents a mini racer crash
|
// This prevents a mini racer crash
|
||||||
export default {};
|
export default {};
|
||||||
|
|
Loading…
Reference in New Issue