allow enter to remove current block if its empty useful for lists
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
8d4cead105
commit
688776bc10
1 changed files with 17 additions and 16 deletions
|
@ -992,24 +992,25 @@ export default class MessageComposerInput extends React.Component {
|
||||||
|
|
||||||
const editorState = this.state.editorState;
|
const editorState = this.state.editorState;
|
||||||
|
|
||||||
let inBlock = false;
|
const lastBlock = editorState.blocks.last();
|
||||||
let inEmptyBlock = false;
|
if (['code', 'block-quote', 'list-item'].includes(lastBlock.type)) {
|
||||||
|
const text = lastBlock.text;
|
||||||
for (const block of editorState.blocks) {
|
if (text === '') {
|
||||||
if (['code', 'block-quote', 'list-item'].includes(block.type)) {
|
// allow the user to cancel empty block by hitting return, useful in conjunction with below `inBlock`
|
||||||
inBlock = true;
|
return change
|
||||||
if (block.text === '') {
|
.setBlocks(DEFAULT_NODE)
|
||||||
inEmptyBlock = true;
|
.unwrapBlock('bulleted-list')
|
||||||
}
|
.unwrapBlock('numbered-list');
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (inEmptyBlock) {
|
// TODO strip trailing lines from blockquotes/list entries
|
||||||
// allow the user to cancel empty block by hitting return, useful in conjunction with below `inBlock`
|
// the below code seemingly works but doesn't account for edge cases like return with caret not at end
|
||||||
return change.setBlocks(DEFAULT_NODE);
|
/* const trailingNewlines = text.match(/\n*$/);
|
||||||
} else if (inBlock) {
|
if (trailingNewlines && trailingNewlines[0]) {
|
||||||
// allow the user to terminate blocks by hitting return rather than sending a msg
|
remove trailing newlines at the end of this block before making a new one
|
||||||
|
return change.deleteBackward(trailingNewlines[0].length);
|
||||||
|
}*/
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue