Skip to content

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

editor: allow tabbing inside editor

Abdullah Atta5db1a7b345ea
diff --git a/packages/editor/src/extensions/key-map/index.ts b/packages/editor/src/extensions/key-map/index.ts
new file mode 100644
index 000000000..3d8631cb7
--- /dev/null
+++ b/packages/editor/src/extensions/key-map/index.ts
@@ -0,0 +1,20 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2022 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+export * from "./key-map";
diff --git a/packages/editor/src/extensions/key-map/key-map.ts b/packages/editor/src/extensions/key-map/key-map.ts
new file mode 100644
index 000000000..e2c003c70
--- /dev/null
+++ b/packages/editor/src/extensions/key-map/key-map.ts
@@ -0,0 +1,32 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2022 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { Extension } from "@tiptap/core";
+
+export const KeyMap = Extension.create({
+ name: "key-map",
+
+ addKeyboardShortcuts() {
+ return {
+ Tab: ({ editor }) => {
+ return editor.commands.insertContent("\t");
+ }
+ };
+ }
+});
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts
index c410392ba..f2b165256 100644
--- a/packages/editor/src/index.ts
+++ b/packages/editor/src/index.ts
@@ -73,6 +73,7 @@ import { Code } from "@tiptap/extension-code";
import { DateTime } from "./extensions/date-time";
import { OpenLink, OpenLinkOptions } from "./extensions/open-link";
import HorizontalRule from "@tiptap/extension-horizontal-rule";
+import { KeyMap } from "./extensions/key-map";
const CoreExtensions = Object.entries(TiptapCoreExtensions)
// we will implement our own customized clipboard serializer
@@ -222,7 +223,8 @@ const useTiptap = (
MathBlock,
KeepInView,
SelectionPersist,
- DateTime
+ DateTime,
+ KeyMap
],
onBeforeCreate: ({ editor }) => {
editor.storage.portalProviderAPI = PortalProviderAPI;