Fix issue with dropping images within uneditable nodes not attaching them #822

This commit is contained in:
Ben Gotow 2018-07-14 12:58:27 -07:00
parent 113d1d9475
commit f6105daa14
3 changed files with 12 additions and 2 deletions

View file

@ -430,12 +430,14 @@ export default class ComposerView extends React.Component {
// Accept drops of real files from other applications
for (const file of Array.from(event.dataTransfer.files)) {
this._onFileReceived(file.path);
event.preventDefault();
}
// Accept drops from attachment components / images within the app
const uri = this._nonNativeFilePathForDrop(event);
if (uri) {
this._onFileReceived(uri);
event.preventDefault();
}
};
@ -452,7 +454,6 @@ export default class ComposerView extends React.Component {
if (!match) {
return;
}
match.contentId = Utils.generateContentId();
session.changes.add({
files: [].concat(draft.files),

View file

@ -264,7 +264,7 @@ export function allNodesInBFSOrder(value) {
return all;
}
function isQuoteNode(n) {
export function isQuoteNode(n) {
return (
n.type === 'blockquote' ||
(n.data && n.data.get('className') && n.data.get('className').includes('gmail_quote'))

View file

@ -1,6 +1,7 @@
import React from 'react';
import { ImageAttachmentItem } from 'mailspring-component-kit';
import { AttachmentStore } from 'mailspring-exports';
import { isQuoteNode } from './base-block-plugins';
const IMAGE_TYPE = 'image';
@ -67,6 +68,14 @@ const rules = [
export const changes = {
insert: (change, file) => {
const canHoldInline = node => !node.isVoid && !isQuoteNode(node) && !!node.getFirstText();
while (!canHoldInline(change.value.anchorBlock)) {
change.collapseToEndOfPreviousText();
if (!change.value.anchorBlock) {
break;
}
}
return change.insertInline({
object: 'inline',
isVoid: true,