fix focus and too many <p>s after a Event>Quote in RT mode

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-07-24 15:54:24 +01:00
parent 6a0182a653
commit 020e714b85
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E

View file

@ -387,17 +387,28 @@ export default class MessageComposerInput extends React.Component {
const anchorText = editorState.anchorText;
if ((!anchorText || anchorText.text === '') && editorState.anchorBlock.nodes.size === 1) {
// replace the current block rather than split the block
// XXX: this destroys our focus by deleting the thing we are anchored/focused on
change = change.replaceNodeByKey(editorState.anchorBlock.key, quote);
}
else {
} else {
// insert it into the middle of the block (splitting it)
change = change.insertBlock(quote);
}
change = change.insertFragmentByKey(quote.key, 0, fragment.document)
.focus();
// XXX: heuristic to strip out wrapping <p> which breaks quoting in RT mode
if (fragment.document.nodes.size && fragment.document.nodes.get(0).type === DEFAULT_NODE) {
change = change.insertFragmentByKey(quote.key, 0, fragment.document.nodes.get(0));
} else {
change = change.insertFragmentByKey(quote.key, 0, fragment.document);
}
// XXX: this is to bring back the focus in a sane place and add a paragraph after it
change = change.select({
anchorKey: quote.key,
focusKey: quote.key,
}).collapseToEndOfBlock().insertBlock(Block.create(DEFAULT_NODE)).focus();
this.onChange(change);
}
else {
} else {
let fragmentChange = fragment.change();
fragmentChange.moveToRangeOf(fragment.document)
.wrapBlock(quote);