From ff76b6a981f99a2c4ffc6ee827658f0aeed46e9f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 17 Jul 2018 12:30:22 +0100 Subject: [PATCH] allow user to break out of blockquote/etc by hitting enter twice Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/rooms/MessageComposerInput.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 5d6b12f339..2fae59a1fe 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -990,15 +990,29 @@ export default class MessageComposerInput extends React.Component { return change.insertText('\n'); } - if (this.state.editorState.blocks.some( - block => ['code', 'block-quote', 'list-item'].includes(block.type) - )) { + const editorState = this.state.editorState; + + let inBlock = false; + let inEmptyBlock = false; + + for (const block of editorState.blocks) { + if (['code', 'block-quote', 'list-item'].includes(block.type)) { + inBlock = true; + if (block.text === '') { + inEmptyBlock = true; + } + break; + } + } + + if (inEmptyBlock) { + // allow the user to cancel empty block by hitting return, useful in conjunction with below `inBlock` + return change.setBlocks(DEFAULT_NODE); + } else if (inBlock) { // allow the user to terminate blocks by hitting return rather than sending a msg return; } - const editorState = this.state.editorState; - let contentText; let contentHTML;