A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: persist text alignment & direction on heading creation
Abdullah Atta9b5e2c108b9e
diff --git a/packages/editor/src/extensions/heading/heading.ts b/packages/editor/src/extensions/heading/heading.tsnew file mode 100644index 000000000..f0ee16dbf--- /dev/null+++ b/packages/editor/src/extensions/heading/heading.ts@@ -0,0 +1,44 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 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 { Heading as TiptapHeading } from "@tiptap/extension-heading";++export const Heading = TiptapHeading.extend({+ addCommands() {+ return {+ ...this.parent?.(),+ setHeading:+ (attributes) =>+ ({ commands, state }) => {+ if (!this.options.levels.includes(attributes.level)) {+ return false;+ }++ const { textAlign, textDirection } =+ state.selection.$from.parent.attrs;++ return commands.setNode(this.name, {+ ...attributes,+ textAlign,+ textDirection+ });+ }+ };+ }+});diff --git a/packages/editor/src/extensions/heading/index.ts b/packages/editor/src/extensions/heading/index.tsnew file mode 100644index 000000000..e70635bfd--- /dev/null+++ b/packages/editor/src/extensions/heading/index.ts@@ -0,0 +1,20 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 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 "./heading";diff --git a/packages/editor/src/extensions/text-direction/text-direction.ts b/packages/editor/src/extensions/text-direction/text-direction.tsindex 14f40b960..0f758e7a5 100644--- a/packages/editor/src/extensions/text-direction/text-direction.ts+++ b/packages/editor/src/extensions/text-direction/text-direction.ts@@ -90,6 +90,7 @@ export const TextDirection = Extension.create<TextDirectionOptions>({// on Android for some keyboards (GBoard etc.). Empty string works fine.default: this.options.defaultDirection || "",parseHTML: (element) => element.dir,+ keepOnSplit: true,renderHTML: (attributes) => {if (!attributes.textDirection) {return {};diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex 761da1e3a..fd83f86b1 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -75,6 +75,7 @@ import { usePermissionHandler } from "./hooks/use-permission-handler";import Toolbar from "./toolbar";import { useToolbarStore } from "./toolbar/stores/toolbar-store";import { DownloadOptions } from "./utils/downloader";+import { Heading } from "./extensions/heading";declare global {// eslint-disable-next-line no-var@@ -155,6 +156,7 @@ const useTiptap = (bulletList: false,paragraph: false,hardBreak: false,+ heading: false,history: {depth: 200,newGroupDelay: 1000@@ -164,6 +166,7 @@ const useTiptap = (},horizontalRule: false}),+ Heading,HorizontalRule.extend({addInputRules() {return [