Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: show keyboard shortcuts for tools where possible

Abdullah Atta885aa3035eff
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.ts
index 953810ef8..d5feed476 100644
--- a/packages/editor/src/extensions/attachment/attachment.ts
+++ b/packages/editor/src/extensions/attachment/attachment.ts
@@ -182,6 +182,12 @@ export const AttachmentNode = Node.create<AttachmentOptions>({
return this.options.onPreviewAttachment(editor, attachment);
}
};
+ },
+
+ addKeyboardShortcuts() {
+ return {
+ "Mod-Shift-A": () => this.editor.commands.openAttachmentPicker("file")
+ };
}
// addInputRules() {
diff --git a/packages/editor/src/extensions/code-block/code-block.ts b/packages/editor/src/extensions/code-block/code-block.ts
index 6fce25816..7eeaadd67 100644
--- a/packages/editor/src/extensions/code-block/code-block.ts
+++ b/packages/editor/src/extensions/code-block/code-block.ts
@@ -282,7 +282,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
addKeyboardShortcuts() {
return {
- "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
+ "Mod-Shift-C": () => this.editor.commands.toggleCodeBlock(),
"Mod-a": ({ editor }) => {
const { $anchor } = this.editor.state.selection;
if ($anchor.parent.type.name !== this.name) {
diff --git a/packages/editor/src/extensions/image/image.ts b/packages/editor/src/extensions/image/image.ts
index 9cfc290fc..a4c47d906 100644
--- a/packages/editor/src/extensions/image/image.ts
+++ b/packages/editor/src/extensions/image/image.ts
@@ -283,5 +283,11 @@ export const ImageNode = Node.create<ImageOptions>({
}
})
];
+ },
+
+ addKeyboardShortcuts() {
+ return {
+ "Mod-Shift-I": () => this.editor.commands.openAttachmentPicker("image")
+ };
}
});
diff --git a/packages/editor/src/extensions/math/math-block.ts b/packages/editor/src/extensions/math/math-block.ts
index 7d878a242..be0312ff8 100644
--- a/packages/editor/src/extensions/math/math-block.ts
+++ b/packages/editor/src/extensions/math/math-block.ts
@@ -64,6 +64,12 @@ export const MathBlock = Node.create({
};
},
+ addKeyboardShortcuts() {
+ return {
+ "Mod-Shift-M": () => this.editor.commands.insertMathBlock()
+ };
+ },
+
addInputRules() {
return [
{
diff --git a/packages/editor/src/extensions/outline-list/outline-list.ts b/packages/editor/src/extensions/outline-list/outline-list.ts
index f11f7051c..c4c5a68a5 100644
--- a/packages/editor/src/extensions/outline-list/outline-list.ts
+++ b/packages/editor/src/extensions/outline-list/outline-list.ts
@@ -103,6 +103,7 @@ export const OutlineList = Node.create<OutlineListOptions>({
"Mod-Shift-O": () => this.editor.commands.toggleOutlineList()
};
},
+
addInputRules() {
return [
wrappingInputRule({
diff --git a/packages/editor/src/extensions/task-list/task-list.ts b/packages/editor/src/extensions/task-list/task-list.ts
index 897aeeb79..44a34a08b 100644
--- a/packages/editor/src/extensions/task-list/task-list.ts
+++ b/packages/editor/src/extensions/task-list/task-list.ts
@@ -214,6 +214,12 @@ export const TaskListNode = TaskList.extend({
});
};
return [inputRule];
+ },
+
+ addKeyboardShortcuts() {
+ return {
+ "Mod-Shift-T": () => this.editor.commands.toggleTaskList()
+ };
}
});
diff --git a/packages/editor/src/toolbar/tools/block.tsx b/packages/editor/src/toolbar/tools/block.tsx
index 66b11523b..c567c5507 100644
--- a/packages/editor/src/toolbar/tools/block.tsx
+++ b/packages/editor/src/toolbar/tools/block.tsx
@@ -111,7 +111,8 @@ const codeblock = (editor: Editor): MenuItem => ({
title: "Code block",
icon: Icons.codeblock,
isChecked: editor?.isActive("codeBlock"),
- onClick: () => editor.current?.chain().focus().toggleCodeBlock().run()
+ onClick: () => editor.current?.chain().focus().toggleCodeBlock().run(),
+ modifier: "Mod-Shift-C"
});
const blockquote = (editor: Editor): MenuItem => ({
@@ -120,7 +121,8 @@ const blockquote = (editor: Editor): MenuItem => ({
title: "Quote",
icon: Icons.blockquote,
isChecked: editor?.isActive("blockQuote"),
- onClick: () => editor.current?.chain().focus().toggleBlockquote().run()
+ onClick: () => editor.current?.chain().focus().toggleBlockquote().run(),
+ modifier: "Mod-Shift-B"
});
const mathblock = (editor: Editor): MenuItem => ({
@@ -129,7 +131,8 @@ const mathblock = (editor: Editor): MenuItem => ({
title: "Math & formulas",
icon: Icons.mathBlock,
isChecked: editor?.isActive("mathBlock"),
- onClick: () => editor.current?.chain().focus().insertMathBlock().run()
+ onClick: () => editor.current?.chain().focus().insertMathBlock().run(),
+ modifier: "Mod-Shift-M"
});
const image = (editor: Editor, isMobile: boolean): MenuItem => ({
@@ -146,7 +149,8 @@ const image = (editor: Editor, isMobile: boolean): MenuItem => ({
title: "Upload from disk",
icon: Icons.upload,
onClick: () =>
- editor.current?.chain().focus().openAttachmentPicker("image").run()
+ editor.current?.chain().focus().openAttachmentPicker("image").run(),
+ modifier: "Mod-Shift-I"
},
{
key: "camera",
@@ -250,7 +254,8 @@ const attachment = (editor: Editor): MenuItem => ({
icon: Icons.attachment,
isChecked: editor?.isActive("attachment"),
onClick: () =>
- editor.current?.chain().focus().openAttachmentPicker("file").run()
+ editor.current?.chain().focus().openAttachmentPicker("file").run(),
+ modifier: "Mod-Shift-A"
});
const tasklist = (editor: Editor): MenuItem => ({
@@ -259,7 +264,8 @@ const tasklist = (editor: Editor): MenuItem => ({
title: "Task list",
icon: Icons.checkbox,
isChecked: editor?.isActive("taskList"),
- onClick: () => editor.current?.chain().focus().toggleTaskList().run()
+ onClick: () => editor.current?.chain().focus().toggleTaskList().run(),
+ modifier: "Mod-Shift-T"
});
const outlinelist = (editor: Editor): MenuItem => ({
@@ -268,7 +274,8 @@ const outlinelist = (editor: Editor): MenuItem => ({
title: "Outline list",
icon: Icons.outlineList,
isChecked: editor?.isActive("outlineList"),
- onClick: () => editor.current?.chain().focus().toggleOutlineList().run()
+ onClick: () => editor.current?.chain().focus().toggleOutlineList().run(),
+ modifier: "Mod-Shift-O"
});
const uploadImageFromURLMobile = (editor: Editor): MenuItem => ({
diff --git a/packages/editor/src/toolbar/tools/headings.tsx b/packages/editor/src/toolbar/tools/headings.tsx
index 706b3dd67..3f7a597a6 100644
--- a/packages/editor/src/toolbar/tools/headings.tsx
+++ b/packages/editor/src/toolbar/tools/headings.tsx
@@ -62,6 +62,7 @@ function toMenuItems(
key: `heading-${level}`,
title: toolbarLocation === "bottom" ? `H${level}` : `Heading ${level}`,
isChecked: level === currentHeadingLevel,
+ modifier: `Mod-Alt-${level}`,
onClick: () =>
editor.current
?.chain()
@@ -75,6 +76,7 @@ function toMenuItems(
type: "button",
title: "Paragraph",
isChecked: !currentHeadingLevel,
+ modifier: `Mod-Alt-0`,
onClick: () => editor.current?.chain().focus().setParagraph().run()
};
return [paragraph, ...menuItems];