fix Control-Backspace after select-all

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

(cherry picked from commit 0f32ec0)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-07-04 10:17:05 +01:00
parent faf17f06c6
commit 43204ea177
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E

View file

@ -713,22 +713,6 @@ export default class MessageComposerInput extends React.Component {
this.direction = '';
}
if (isOnlyCtrlOrCmdKeyEvent(ev)) {
const ctrlCmdCommand = {
// C-m => Toggles between rich text and markdown modes
[KeyCode.KEY_M]: 'toggle-mode',
[KeyCode.KEY_B]: 'bold',
[KeyCode.KEY_I]: 'italic',
[KeyCode.KEY_U]: 'underlined',
[KeyCode.KEY_J]: 'inline-code',
}[ev.keyCode];
if (ctrlCmdCommand) {
return this.handleKeyCommand(ctrlCmdCommand);
}
return;
}
switch (ev.keyCode) {
case KeyCode.ENTER:
return this.handleReturn(ev, change);
@ -744,9 +728,21 @@ export default class MessageComposerInput extends React.Component {
return this.onEscape(ev);
case KeyCode.SPACE:
return this.onSpace(ev, change);
default:
// don't intercept it
return;
}
if (isOnlyCtrlOrCmdKeyEvent(ev)) {
const ctrlCmdCommand = {
// C-m => Toggles between rich text and markdown modes
[KeyCode.KEY_M]: 'toggle-mode',
[KeyCode.KEY_B]: 'bold',
[KeyCode.KEY_I]: 'italic',
[KeyCode.KEY_U]: 'underlined',
[KeyCode.KEY_J]: 'inline-code',
}[ev.keyCode];
if (ctrlCmdCommand) {
return this.handleKeyCommand(ctrlCmdCommand);
}
}
};
@ -757,15 +753,22 @@ export default class MessageComposerInput extends React.Component {
return change.setOperationFlag("skip", false).setOperationFlag("merge", false).insertText(ev.key);
};
onBackspace = (ev: Event, change: Change): Change => {
if (ev.ctrlKey || ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) {
onBackspace = (ev: KeyboardEvent, change: Change): Change => {
if (ev.metaKey || ev.altKey || ev.shiftKey) {
return;
}
const { editorState } = this.state;
// Allow Ctrl/Cmd-Backspace when focus starts at the start of the composer (e.g select-all)
// for some reason if slate sees you Ctrl-backspace and your anchorOffset=0 it just resets your focus
if (!editorState.isCollapsed && editorState.anchorOffset === 0) {
return change.delete();
}
if (this.state.isRichTextEnabled) {
// let backspace exit lists
const isList = this.hasBlock('list-item');
const { editorState } = this.state;
if (isList && editorState.anchorOffset == 0) {
change