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: font ligatures for common symbols (#7800)
01zulfid5a719c9f609
diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 461497431..9fbfdc18b 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -104,6 +104,7 @@ type TipTapProps = {dateFormat: string;timeFormat: TimeFormat;markdownShortcuts: boolean;+ fontLigatures: boolean;};function updateWordCount(id: string, content: () => Fragment) {@@ -145,7 +146,8 @@ function TipTap(props: TipTapProps) {doubleSpacedLines,dateFormat,timeFormat,- markdownShortcuts+ markdownShortcuts,+ fontLigatures} = props;const isUserPremium = useIsUserPremium();@@ -193,6 +195,7 @@ function TipTap(props: TipTapProps) {}},enableInputRules: markdownShortcuts,+ enableFontLigatures: fontLigatures,downloadOptions,doubleSpacedLines,dateFormat,@@ -313,7 +316,8 @@ function TipTap(props: TipTapProps) {doubleSpacedLines,dateFormat,timeFormat,- markdownShortcuts+ markdownShortcuts,+ fontLigatures]);const editor = useTiptap(@@ -435,6 +439,7 @@ function TiptapWrapper(const markdownShortcuts = useSettingsStore((store) => store.markdownShortcuts);+ const fontLigatures = useSettingsStore((store) => store.fontLigatures);const containerRef = useRef<HTMLDivElement>(null);const editorContainerRef = useRef<HTMLDivElement>();const { editorConfig, setEditorConfig } = useEditorConfig();@@ -509,7 +514,7 @@ function TiptapWrapper(}}><TipTap- key={`tiptap-${props.id}-${doubleSpacedLines}-${dateFormat}-${timeFormat}-${markdownShortcuts}`}+ key={`tiptap-${props.id}-${doubleSpacedLines}-${dateFormat}-${timeFormat}-${markdownShortcuts}-${fontLigatures}`}{...props}isMobile={isMobile}isTablet={isTablet}@@ -517,6 +522,7 @@ function TiptapWrapper(dateFormat={dateFormat}timeFormat={timeFormat}markdownShortcuts={markdownShortcuts}+ fontLigatures={fontLigatures}onLoad={(editor) => {if (!isHydrating) {onLoad?.(editor);diff --git a/apps/web/src/dialogs/settings/editor-settings.ts b/apps/web/src/dialogs/settings/editor-settings.tsindex a96e65d6f..ae9ac828e 100644--- a/apps/web/src/dialogs/settings/editor-settings.ts+++ b/apps/web/src/dialogs/settings/editor-settings.ts@@ -121,6 +121,20 @@ export const EditorSettings: SettingsGroup[] = [toggle: () => useSettingStore.getState().toggleMarkdownShortcuts()}]+ },+ {+ key: "font-ligatures",+ title: strings.fontLigatures(),+ description: strings.fontLigaturesDesc(),+ onStateChange: (listener) =>+ useSettingStore.subscribe((c) => c.fontLigatures, listener),+ components: [+ {+ type: "toggle",+ isToggled: () => useSettingStore.getState().fontLigatures,+ toggle: () => useSettingStore.getState().toggleFontLigatures()+ }+ ]}]},diff --git a/apps/web/src/stores/setting-store.ts b/apps/web/src/stores/setting-store.tsindex b71d0402c..a7909e1a9 100644--- a/apps/web/src/stores/setting-store.ts+++ b/apps/web/src/stores/setting-store.ts@@ -52,6 +52,7 @@ class SettingStore extends BaseStore<SettingStore> {);doubleSpacedParagraphs = Config.get("doubleSpacedLines", true);markdownShortcuts = Config.get("markdownShortcuts", true);+ fontLigatures = Config.get("fontLigatures", false);notificationsSettings = Config.get("notifications", { reminder: true });isFullOfflineMode = Config.get("fullOfflineMode", false);serverUrls: Partial<Record<HostId, string>> = Config.get("serverUrls", {});@@ -199,6 +200,12 @@ class SettingStore extends BaseStore<SettingStore> {Config.set("markdownShortcuts", !markdownShortcuts);};+ toggleFontLigatures = () => {+ const fontLigatures = this.get().fontLigatures;+ this.set((state) => (state.fontLigatures = !fontLigatures));+ Config.set("fontLigatures", !fontLigatures);+ };+togglePrivacyMode = async () => {const privacyMode = this.get().privacyMode;this.set({ privacyMode: !privacyMode });diff --git a/packages/editor/src/extensions/font-ligature/font-ligature.ts b/packages/editor/src/extensions/font-ligature/font-ligature.tsnew file mode 100644index 000000000..446b5a0af--- /dev/null+++ b/packages/editor/src/extensions/font-ligature/font-ligature.ts@@ -0,0 +1,53 @@+/*+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 { Extension } from "@tiptap/core";++const ligatures = {+ "->": "→",+ "<-": "←",+ "<=": "≤",+ ">=": "≥",+ "!=": "≠",+ "==>": "⟹",+ "<==": "⟸",+ "--": "—"+};++export const FontLigature = Extension.create({+ name: "fontLigature",++ addOptions() {+ return {+ enabled: false+ };+ },++ addInputRules() {+ if (!this.options.enabled) return [];++ return Object.entries(ligatures).map(([from, to]) => ({+ find: new RegExp(`${from}$`),+ handler: ({ state, range }) => {+ const { from: start, to: end } = range;+ state.tr.replaceRangeWith(start, end, state.schema.text(to));+ }+ }));+ }+});diff --git a/packages/editor/src/extensions/font-ligature/index.ts b/packages/editor/src/extensions/font-ligature/index.tsnew file mode 100644index 000000000..84e9c704c--- /dev/null+++ b/packages/editor/src/extensions/font-ligature/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 "./font-ligature.js";diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex 36a1ed0ac..01457abc9 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -85,6 +85,7 @@ import { DiffHighlighter } from "./extensions/diff-highlighter/index.js";import { getChangedNodes } from "./utils/prosemirror.js";import { strings } from "@notesnook/intl";import { InlineCode } from "./extensions/inline-code/inline-code.js";+import { FontLigature } from "./extensions/font-ligature/font-ligature.js";interface TiptapStorage {dateFormat?: DateTimeOptions["dateFormat"];@@ -127,6 +128,7 @@ export type TiptapOptions = EditorOptions &downloadOptions?: DownloadOptions;isMobile?: boolean;doubleSpacedLines?: boolean;+ enableFontLigatures?: boolean;} & {placeholder: string;};@@ -151,6 +153,7 @@ const useTiptap = (isMobile,downloadOptions,editorProps,+ enableFontLigatures,...restOptions} = options;@@ -355,7 +358,8 @@ const useTiptap = (wrapperNames: [CheckList.name]}]- })+ }),+ FontLigature.configure({ enabled: enableFontLigatures })],onBeforeCreate: ({ editor }) => {editor.storage.dateFormat = dateFormat;diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.poindex 8ad5c55de..8a1bc9d74 100644--- a/packages/intl/locale/en.po+++ b/packages/intl/locale/en.po@@ -2304,6 +2304,10 @@ msgstr "Enable app lock"msgid "Enable editor margins"msgstr "Enable editor margins"+#: src/strings.ts:2443+msgid "Enable ligatures for common symbols like →, ←, etc"+msgstr "Enable ligatures for common symbols like →, ←, etc"+#: src/strings.ts:2361msgid "Enable regex"msgstr "Enable regex"@@ -2718,6 +2722,10 @@ msgstr "Follow us on X for updates and news about Notesnook"msgid "Font family"msgstr "Font family"+#: src/strings.ts:2442+msgid "Font ligatures"+msgstr "Font ligatures"+#: src/strings.ts:2256msgid "Font size"msgstr "Font size"diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.poindex 4f03f6fe1..26a24a5e1 100644--- a/packages/intl/locale/pseudo-LOCALE.po+++ b/packages/intl/locale/pseudo-LOCALE.po@@ -2293,6 +2293,10 @@ msgstr ""msgid "Enable editor margins"msgstr ""+#: src/strings.ts:2443+msgid "Enable ligatures for common symbols like →, ←, etc"+msgstr ""+#: src/strings.ts:2361msgid "Enable regex"msgstr ""@@ -2707,6 +2711,10 @@ msgstr ""msgid "Font family"msgstr ""+#: src/strings.ts:2442+msgid "Font ligatures"+msgstr ""+#: src/strings.ts:2256msgid "Font size"msgstr ""diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.tsindex c092bb68c..e635edcd7 100644--- a/packages/intl/src/strings.ts+++ b/packages/intl/src/strings.ts@@ -2439,5 +2439,7 @@ Use this if changes from other devices are not appearing on this device. This wistable: () => t`Stable`,beta: () => t`Beta`,zoom: () => t`Zoom`,- toggleFocusMode: () => t`Toggle focus mode`+ toggleFocusMode: () => t`Toggle focus mode`,+ fontLigatures: () => t`Font ligatures`,+ fontLigaturesDesc: () => t`Enable ligatures for common symbols like →, ←, etc`};