mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-28 11:24:11 +08:00
Solution for applying HTML to drafts that does not nest incoming nodes
This commit is contained in:
parent
2dd6104b20
commit
c3577f579f
1 changed files with 6 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
import MailspringStore from 'mailspring-store';
|
import MailspringStore from 'mailspring-store';
|
||||||
import { Editor, Value } from 'slate';
|
import { Editor, Value, Block } from 'slate';
|
||||||
|
|
||||||
import RegExpUtils from '../../regexp-utils';
|
import RegExpUtils from '../../regexp-utils';
|
||||||
import { localized } from '../../intl';
|
import { localized } from '../../intl';
|
||||||
|
@ -79,15 +79,11 @@ function hotwireDraftBodyState(draft: any, session: DraftEditingSession): Messag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [newFirst, ...newRest] = inHTMLEditorValue.document.nodes.toArray();
|
_bodyEditorValue = edits
|
||||||
|
.replaceNodeByKey(first.key, Block.create({ type: 'div' }))
|
||||||
// replace the first node in the document with the first node of the new
|
.moveToRangeOfDocument()
|
||||||
// document, and then "insert" the remaining new nodes at the end.
|
.insertFragment(inHTMLEditorValue.document)
|
||||||
edits = edits.replaceNodeByKey(first.key, newFirst).moveToEndOfDocument();
|
.moveToStart().value;
|
||||||
for (const block of newRest) {
|
|
||||||
edits = edits.insertBlock(block);
|
|
||||||
}
|
|
||||||
_bodyEditorValue = edits.moveToStart().value;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// deleting and re-inserting the whole document seems to push Slate pretty hard and it
|
// deleting and re-inserting the whole document seems to push Slate pretty hard and it
|
||||||
// sometimes fails with odd schema issues (undefined node, invalid range.) Just fall
|
// sometimes fails with odd schema issues (undefined node, invalid range.) Just fall
|
||||||
|
|
Loading…
Reference in a new issue