mirror of
https://github.com/discourse/discourse.git
synced 2025-03-15 04:45:27 +08:00
Skip HTML pasting if image upload available
This commit is contained in:
parent
91e84433ff
commit
236ecec0b0
@ -432,9 +432,9 @@ export default Ember.Component.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { types } = clipboardData(e);
|
const { types, canUpload, canPasteHtml } = clipboardData(e, true);
|
||||||
|
|
||||||
if (types.includes("text/plain") || (types.includes("text/html") && this.siteSettings.enable_rich_text_paste)) {
|
if (!canUpload || canPasteHtml) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -655,7 +655,9 @@ export default Ember.Component.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { clipboard, types } = clipboardData(e);
|
const isComposer = $("#reply-control .d-editor-input").is(":focus");
|
||||||
|
const { clipboard, canPasteHtml } = clipboardData(e, isComposer);
|
||||||
|
|
||||||
let plainText = clipboard.getData("text/plain");
|
let plainText = clipboard.getData("text/plain");
|
||||||
let html = clipboard.getData("text/html");
|
let html = clipboard.getData("text/html");
|
||||||
let handled = false;
|
let handled = false;
|
||||||
@ -671,7 +673,7 @@ export default Ember.Component.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.siteSettings.enable_rich_text_paste && html && !handled) {
|
if (canPasteHtml && !handled) {
|
||||||
const markdown = toMarkdown(html);
|
const markdown = toMarkdown(html);
|
||||||
|
|
||||||
if (!plainText || plainText.length < markdown.length) {
|
if (!plainText || plainText.length < markdown.length) {
|
||||||
@ -680,9 +682,7 @@ export default Ember.Component.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadFiles = types.includes("Files") && !plainText && !handled;
|
if (handled) {
|
||||||
|
|
||||||
if (handled || uploadFiles) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -421,18 +421,27 @@ export function isAppleDevice() {
|
|||||||
!navigator.userAgent.match(/Trident/g);
|
!navigator.userAgent.match(/Trident/g);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clipboardData(e) {
|
export function clipboardData(e, canUpload) {
|
||||||
const clipboard = e.clipboardData ||
|
const clipboard = e.clipboardData ||
|
||||||
e.originalEvent.clipboardData ||
|
e.originalEvent.clipboardData ||
|
||||||
e.delegatedEvent.originalEvent.clipboardData;
|
e.delegatedEvent.originalEvent.clipboardData;
|
||||||
|
|
||||||
let types = clipboard.types;
|
let types = clipboard.types;
|
||||||
|
let files = clipboard.files;
|
||||||
|
|
||||||
if (!Array.isArray(types)) {
|
if (!Array.isArray(types)) {
|
||||||
types = Array.from(types);
|
types = Array.from(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { clipboard: clipboard, types: types };
|
if (!Array.isArray(files)) {
|
||||||
|
files = Array.from(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
canUpload = files && canUpload && !types.includes("text/plain");
|
||||||
|
const canUploadImage = canUpload && files.filter(f => f.type.match('^image/'))[0];
|
||||||
|
const canPasteHtml = Discourse.SiteSettings.enable_rich_text_paste && types.includes("text/html") && !canUploadImage;
|
||||||
|
|
||||||
|
return { clipboard: clipboard, types: types, canUpload: canUpload, canPasteHtml: canPasteHtml };
|
||||||
}
|
}
|
||||||
|
|
||||||
// This prevents a mini racer crash
|
// This prevents a mini racer crash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user