<BlockButton
format={BlockType.BlockQuote}
icon={Icons.BlockQuote}
- tooltip={
- <BtnTooltip text="Block Quote" shortCode={`${modKey} + ${KeySymbol.Shift} + '`} />
- }
+ tooltip={<BtnTooltip text="Block Quote" shortCode={`${modKey} + '`} />}
/>
<BlockButton
format={BlockType.CodeBlock}
icon={Icons.BlockCode}
- tooltip={
- <BtnTooltip text="Block Code" shortCode={`${modKey} + ${KeySymbol.Shift} + ;`} />
- }
+ tooltip={<BtnTooltip text="Block Code" shortCode={`${modKey} + ;`} />}
/>
<BlockButton
format={BlockType.OrderedList}
icon={Icons.OrderList}
- tooltip={
- <BtnTooltip text="Ordered List" shortCode={`${modKey} + ${KeySymbol.Shift} + 7`} />
- }
+ tooltip={<BtnTooltip text="Ordered List" shortCode={`${modKey} + 7`} />}
/>
<BlockButton
format={BlockType.UnorderedList}
icon={Icons.UnorderList}
- tooltip={
- <BtnTooltip
- text="Unordered List"
- shortCode={`${modKey} + ${KeySymbol.Shift} + 8`}
- />
- }
+ tooltip={<BtnTooltip text="Unordered List" shortCode={`${modKey} + 8`} />}
/>
<HeadingBlockButton />
</Box>
<Line variant="SurfaceVariant" direction="Vertical" style={{ height: toRem(12) }} />
<Box shrink="No" gap="100">
<ExitFormatting
- tooltip={<BtnTooltip text="Exit Formatting" shortCode={`${modKey} + E`} />}
+ tooltip={
+ <BtnTooltip text="Exit Formatting" shortCode={`Escape, ${modKey} + E`} />
+ }
/>
</Box>
</>
import React, { ReactNode } from 'react';
import FocusTrap from 'focus-trap-react';
-import isHotkey from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import { Header, Menu, Scroll, config } from 'folds';
import * as css from './AutocompleteMenu.css';
returnFocusOnDeactivate: false,
clickOutsideDeactivates: true,
allowOutsideClick: true,
- isKeyForward: (evt: KeyboardEvent) => isHotkey('arrowdown', evt),
- isKeyBackward: (evt: KeyboardEvent) => isHotkey('arrowup', evt),
+ isKeyForward: (evt: KeyboardEvent) => isKeyHotkey('arrowdown', evt),
+ isKeyBackward: (evt: KeyboardEvent) => isKeyHotkey('arrowup', evt),
}}
>
<Menu className={css.AutocompleteMenu}>
-import { isHotkey } from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import { KeyboardEvent } from 'react';
-import { Editor } from 'slate';
+import { Editor, Range } from 'slate';
import { isAnyMarkActive, isBlockActive, removeAllMark, toggleBlock, toggleMark } from './utils';
import { BlockType, MarkType } from './types';
const INLINE_KEYS = Object.keys(INLINE_HOTKEYS);
export const BLOCK_HOTKEYS: Record<string, BlockType> = {
- 'mod+shift+7': BlockType.OrderedList,
- 'mod+shift+8': BlockType.UnorderedList,
- "mod+shift+'": BlockType.BlockQuote,
- 'mod+shift+;': BlockType.CodeBlock,
+ 'mod+7': BlockType.OrderedList,
+ 'mod+8': BlockType.UnorderedList,
+ "mod+'": BlockType.BlockQuote,
+ 'mod+;': BlockType.CodeBlock,
};
const BLOCK_KEYS = Object.keys(BLOCK_HOTKEYS);
* @return boolean true if shortcut is toggled.
*/
export const toggleKeyboardShortcut = (editor: Editor, event: KeyboardEvent<Element>): boolean => {
- if (isHotkey('mod+e', event)) {
+ if (isKeyHotkey('backspace', event) && editor.selection && Range.isCollapsed(editor.selection)) {
+ const startPoint = Range.start(editor.selection);
+ if (startPoint.offset !== 0) return false;
+
+ const [parentNode, parentPath] = Editor.parent(editor, startPoint);
+
+ if (Editor.isEditor(parentNode)) return false;
+
+ if (parentNode.type === BlockType.Heading) {
+ toggleBlock(editor, BlockType.Paragraph);
+ return true;
+ }
+ if (
+ parentNode.type === BlockType.CodeLine ||
+ parentNode.type === BlockType.QuoteLine ||
+ parentNode.type === BlockType.ListItem
+ ) {
+ // exit formatting only when line block
+ // is first of last of it's parent
+ const parentLocation = { at: parentPath };
+ const [previousNode] = Editor.previous(editor, parentLocation) ?? [];
+ const [nextNode] = Editor.next(editor, parentLocation) ?? [];
+ if (!previousNode || !nextNode) {
+ toggleBlock(editor, BlockType.Paragraph);
+ return true;
+ }
+ }
+ }
+
+ if (isKeyHotkey('mod+e', event) || isKeyHotkey('escape', event)) {
if (isAnyMarkActive(editor)) {
removeAllMark(editor);
return true;
}
const blockToggled = BLOCK_KEYS.find((hotkey) => {
- if (isHotkey(hotkey, event)) {
+ if (isKeyHotkey(hotkey, event)) {
event.preventDefault();
toggleBlock(editor, BLOCK_HOTKEYS[hotkey]);
return true;
const inlineToggled = isBlockActive(editor, BlockType.CodeBlock)
? false
: INLINE_KEYS.find((hotkey) => {
- if (isHotkey(hotkey, event)) {
+ if (isKeyHotkey(hotkey, event)) {
event.preventDefault();
toggleMark(editor, INLINE_HOTKEYS[hotkey]);
return true;
toRem,
} from 'folds';
import FocusTrap from 'focus-trap-react';
-import isHotkey from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import classNames from 'classnames';
import { MatrixClient, Room } from 'matrix-js-sdk';
import { atom, useAtomValue, useSetAtom } from 'jotai';
clickOutsideDeactivates: true,
allowOutsideClick: true,
isKeyForward: (evt: KeyboardEvent) =>
- !editableActiveElement() && isHotkey(['arrowdown', 'arrowright'], evt),
+ !editableActiveElement() && isKeyHotkey(['arrowdown', 'arrowright'], evt),
isKeyBackward: (evt: KeyboardEvent) =>
- !editableActiveElement() && isHotkey(['arrowup', 'arrowleft'], evt),
+ !editableActiveElement() && isKeyHotkey(['arrowup', 'arrowleft'], evt),
}}
>
<EmojiBoardLayout
useState,
} from 'react';
import { useAtom } from 'jotai';
-import isHotkey from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import { EventType, IContent, MsgType, Room } from 'matrix-js-sdk';
import { ReactEditor } from 'slate-react';
import { Transforms, Editor } from 'slate';
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();
submit();
}
- if (isHotkey('escape', evt)) {
+ if (isKeyHotkey('escape', evt)) {
evt.preventDefault();
setReplyDraft();
}
const handleKeyUp: KeyboardEventHandler = useCallback(
(evt) => {
- if (isHotkey('escape', evt)) {
+ if (isKeyHotkey('escape', evt)) {
evt.preventDefault();
return;
}
config,
toRem,
} from 'folds';
-import isHotkey from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import Linkify from 'linkify-react';
import {
decryptFile,
useCallback(
(evt) => {
if (
- isHotkey('arrowup', evt) &&
+ isKeyHotkey('arrowup', evt) &&
editableActiveElement() &&
document.activeElement?.getAttribute('data-editable-name') === 'RoomInput' &&
isEmptyEditor(editor)
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,
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();
}
const handleKeyUp: KeyboardEventHandler = useCallback(
(evt) => {
- if (isHotkey('escape', evt)) {
+ if (isKeyHotkey('escape', evt)) {
evt.preventDefault();
return;
}
const defaultSettings: Settings = {
themeIndex: 0,
useSystemTheme: true,
- isMarkdown: true,
+ isMarkdown: false,
editorToolbar: false,
useSystemEmoji: false,
-import isHotkey from 'is-hotkey';
+import { isKeyHotkey } from 'is-hotkey';
import { KeyboardEventHandler } from 'react';
export interface KeyboardEventLike {
}
export const onTabPress = (evt: KeyboardEventLike, callback: () => void) => {
- if (isHotkey('tab', evt)) {
+ if (isKeyHotkey('tab', evt)) {
evt.preventDefault();
callback();
}
};
export const preventScrollWithArrowKey: KeyboardEventHandler = (evt) => {
- if (isHotkey(['arrowup', 'arrowright', 'arrowdown', 'arrowleft'], evt)) {
+ if (isKeyHotkey(['arrowup', 'arrowright', 'arrowdown', 'arrowleft'], evt)) {
evt.preventDefault();
}
};