Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 020e714

Browse files
committed
fix focus and too many <p>s after a Event>Quote in RT mode
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 6a0182a commit 020e714

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/components/views/rooms/MessageComposerInput.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,28 @@ export default class MessageComposerInput extends React.Component {
387387
const anchorText = editorState.anchorText;
388388
if ((!anchorText || anchorText.text === '') && editorState.anchorBlock.nodes.size === 1) {
389389
// replace the current block rather than split the block
390+
// XXX: this destroys our focus by deleting the thing we are anchored/focused on
390391
change = change.replaceNodeByKey(editorState.anchorBlock.key, quote);
391-
}
392-
else {
392+
} else {
393393
// insert it into the middle of the block (splitting it)
394394
change = change.insertBlock(quote);
395395
}
396-
change = change.insertFragmentByKey(quote.key, 0, fragment.document)
397-
.focus();
396+
397+
// XXX: heuristic to strip out wrapping <p> which breaks quoting in RT mode
398+
if (fragment.document.nodes.size && fragment.document.nodes.get(0).type === DEFAULT_NODE) {
399+
change = change.insertFragmentByKey(quote.key, 0, fragment.document.nodes.get(0));
400+
} else {
401+
change = change.insertFragmentByKey(quote.key, 0, fragment.document);
402+
}
403+
404+
// XXX: this is to bring back the focus in a sane place and add a paragraph after it
405+
change = change.select({
406+
anchorKey: quote.key,
407+
focusKey: quote.key,
408+
}).collapseToEndOfBlock().insertBlock(Block.create(DEFAULT_NODE)).focus();
409+
398410
this.onChange(change);
399-
}
400-
else {
411+
} else {
401412
let fragmentChange = fragment.change();
402413
fragmentChange.moveToRangeOf(fragment.document)
403414
.wrapBlock(quote);

0 commit comments

Comments
 (0)