Fix hotkeys (#1468)

* use hotkey using key instead of which (default)

* remove shift from block formatting hotkeys

* smartly exit formatting with backspace

* set markdown to off by default

* exit formatting with escape
This commit is contained in:
Ajay Bura 2023-10-21 18:14:33 +11:00 committed by GitHub
commit d5ff55e23e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 45 deletions

View file

@ -3,7 +3,7 @@ import { Box, Chip, Icon, IconButton, Icons, Line, PopOut, Spinner, Text, as, co
import { Editor, Transforms } from 'slate';
import { ReactEditor } from 'slate-react';
import { IContent, MatrixEvent, RelationType, Room } from 'matrix-js-sdk';
import isHotkey from 'is-hotkey';
import { isKeyHotkey } from 'is-hotkey';
import {
AUTOCOMPLETE_PREFIXES,
AutocompletePrefix,
@ -120,11 +120,11 @@ export const MessageEditor = as<'div', MessageEditorProps>(
const handleKeyDown: KeyboardEventHandler = useCallback(
(evt) => {
if (enterForNewline ? isHotkey('shift+enter', evt) : isHotkey('enter', evt)) {
if (enterForNewline ? isKeyHotkey('shift+enter', evt) : isKeyHotkey('enter', evt)) {
evt.preventDefault();
handleSave();
}
if (isHotkey('escape', evt)) {
if (isKeyHotkey('escape', evt)) {
evt.preventDefault();
onCancel();
}
@ -134,7 +134,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
const handleKeyUp: KeyboardEventHandler = useCallback(
(evt) => {
if (isHotkey('escape', evt)) {
if (isKeyHotkey('escape', evt)) {
evt.preventDefault();
return;
}