let backspace delete list nodes in RTE

pull/21833/head
Matthew Hodgson 2018-05-19 20:38:07 +01:00
parent 167742d900
commit a4d9338cf0
1 changed files with 25 additions and 4 deletions

View File

@ -77,6 +77,10 @@ const ENTITY_TYPES = {
AT_ROOM_PILL: 'ATROOMPILL',
};
// the Slate node type to default to for unstyled text when in RTE mode.
// (we use 'line' for oneliners however)
const DEFAULT_NODE = 'paragraph';
function onSendMessageFailed(err, room) {
// XXX: temporary logging to try to diagnose
@ -548,6 +552,8 @@ export default class MessageComposerInput extends React.Component {
switch (ev.keyCode) {
case KeyCode.ENTER:
return this.handleReturn(ev);
case KeyCode.BACKSPACE:
return this.onBackspace(ev);
case KeyCode.UP:
return this.onVerticalArrow(ev, true);
case KeyCode.DOWN:
@ -562,6 +568,23 @@ export default class MessageComposerInput extends React.Component {
}
};
onBackspace = (ev: Event): boolean => {
if (this.state.isRichtextEnabled) {
// let backspace exit lists
const isList = this.hasBlock('list-item');
if (isList) {
const change = this.state.editorState.change();
change
.setBlocks(DEFAULT_NODE)
.unwrapBlock('bulleted-list')
.unwrapBlock('numbered-list');
this.onChange(change);
return true;
}
}
return;
};
handleKeyCommand = (command: string): boolean => {
if (command === 'toggle-mode') {
this.enableRichtext(!this.state.isRichtextEnabled);
@ -570,8 +593,6 @@ export default class MessageComposerInput extends React.Component {
let newState: ?Value = null;
const DEFAULT_NODE = 'paragraph';
// Draft handles rich text mode commands by default but we need to do it ourselves for Markdown.
if (this.state.isRichtextEnabled) {
const type = command;