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: fix cursor position on return
ammarahm-edd2165c99f1b0
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex 13a4d74b8..880e7c207 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -83,6 +83,12 @@ declare global {var keyboardShown: boolean;}+function hasStyle(element: HTMLElement | string) {+ const style = (element as HTMLElement).getAttribute("style");+ if (!style || style === "font-family: inherit;") return false;+ return true;+}+globalThis["keyboardShown"] = true;const CoreExtensions = Object.entries(TiptapCoreExtensions)// we will implement our own customized clipboard serializer@@ -140,124 +146,143 @@ const useTiptap = (}, deps);const defaultOptions = useMemo<Partial<EditorOptions>>(- () => ({- enableCoreExtensions: false,- extensions: [- ...CoreExtensions,- ClipboardTextSerializer,- NodeViewSelectionNotifier,- SearchReplace,- TextStyle,- Paragraph.configure({- doubleSpaced: doubleSpacedLines- }),- StarterKit.configure({- code: false,- codeBlock: false,- listItem: false,- orderedList: false,- bulletList: false,- paragraph: false,- hardBreak: false,- heading: false,- history: {- depth: 200,- newGroupDelay: 1000- },- dropcursor: {- class: "drop-cursor"- },- horizontalRule: false- }),- Heading,- HorizontalRule.extend({- addInputRules() {- return [- {- find: /^(?:---|—-|___\s|\*\*\*\s)$/,- handler: ({ state, range, commands }) => {- commands.splitBlock();+ () =>+ ({+ enableCoreExtensions: false,+ extensions: [+ ...CoreExtensions,+ ClipboardTextSerializer,+ NodeViewSelectionNotifier,+ SearchReplace,+ TextStyle.extend({+ parseHTML() {+ return [+ {+ tag: "span",+ getAttrs: (element) => {+ if (!hasStyle(element)) {+ return false;+ }+ return {};+ }+ }+ ];+ }+ }),+ Paragraph.configure({+ doubleSpaced: doubleSpacedLines+ }),+ StarterKit.configure({+ code: false,+ codeBlock: false,+ listItem: false,+ orderedList: false,+ bulletList: false,+ paragraph: false,+ hardBreak: false,+ heading: false,+ history: {+ depth: 200,+ newGroupDelay: 1000+ },+ dropcursor: {+ class: "drop-cursor"+ },+ horizontalRule: false+ }),+ Heading,+ HorizontalRule.extend({+ addInputRules() {+ return [+ {+ find: /^(?:---|—-|___\s|\*\*\*\s)$/,+ handler: ({ state, range, commands }) => {+ commands.splitBlock();- const attributes = {};- const { tr } = state;- const start = range.from;- const end = range.to;- tr.replaceWith(start - 1, end, this.type.create(attributes));+ const attributes = {};+ const { tr } = state;+ const start = range.from;+ const end = range.to;+ tr.replaceWith(+ start - 1,+ end,+ this.type.create(attributes)+ );+ }}- }- ];- }- }),- CharacterCount,- Underline,- Subscript,- Superscript,- FontSize,- TextDirection,- FontFamily,- BulletList.configure({ keepMarks: true, keepAttributes: true }),- OrderedList.configure({ keepMarks: true, keepAttributes: true }),- TaskItemNode.configure({ nested: true }),- TaskListNode,- Link.extend({- inclusive: true- }).configure({- openOnClick: !isMobile,- autolink: false- }),- Table.configure({- resizable: true,- allowTableNodeSelection: true,- cellMinWidth: 50- }),- Clipboard.configure({- copyToClipboard- }),- TableRow,- TableCell,- TableHeader,- Highlight,- CodeBlock,- Color,- TextAlign.configure({- types: ["heading", "paragraph"],- alignments: ["left", "right", "center", "justify"],- defaultAlignment: "left"- }),- Placeholder.configure({- placeholder: "Start writing your note..."- }),- OpenLink.configure({- onOpenLink- }),- ImageNode.configure({ allowBase64: true }),- EmbedNode,- AttachmentNode.configure({- onDownloadAttachment,- onOpenAttachmentPicker,- onPreviewAttachment- }),- OutlineListItem,- OutlineList.configure({ keepAttributes: true, keepMarks: true }),- ListItem,- Code.extend({ excludes: "" }),- Codemark,- MathInline,- MathBlock,- KeepInView.configure({- scrollIntoViewOnWindowResize: !isMobile- }),- DateTime.configure({ dateFormat, timeFormat }),- KeyMap,- WebClipNode- ],- onBeforeCreate: ({ editor }) => {- editor.storage.portalProviderAPI = PortalProviderAPI;- if (onBeforeCreate) onBeforeCreate({ editor });- },- injectCSS: false,- parseOptions: { preserveWhitespace: true }- }),+ ];+ }+ }),+ CharacterCount,+ Underline,+ Subscript,+ Superscript,+ FontSize,+ TextDirection,+ FontFamily,+ BulletList.configure({ keepMarks: true, keepAttributes: true }),+ OrderedList.configure({ keepMarks: true, keepAttributes: true }),+ TaskItemNode.configure({ nested: true }),+ TaskListNode,+ Link.extend({+ inclusive: true+ }).configure({+ openOnClick: !isMobile,+ autolink: false+ }),+ Table.configure({+ resizable: true,+ allowTableNodeSelection: true,+ cellMinWidth: 50+ }),+ Clipboard.configure({+ copyToClipboard+ }),+ TableRow,+ TableCell,+ TableHeader,+ Highlight,+ CodeBlock,+ Color,+ TextAlign.configure({+ types: ["heading", "paragraph"],+ alignments: ["left", "right", "center", "justify"],+ defaultAlignment: "left"+ }),+ Placeholder.configure({+ placeholder: "Start writing your note..."+ }),+ OpenLink.configure({+ onOpenLink+ }),+ ImageNode.configure({ allowBase64: true }),+ EmbedNode,+ AttachmentNode.configure({+ onDownloadAttachment,+ onOpenAttachmentPicker,+ onPreviewAttachment+ }),+ OutlineListItem,+ OutlineList.configure({ keepAttributes: true, keepMarks: true }),+ ListItem,+ Code.extend({ excludes: "" }),+ Codemark,+ MathInline,+ MathBlock,+ KeepInView.configure({+ scrollIntoViewOnWindowResize: !isMobile+ }),+ DateTime.configure({ dateFormat, timeFormat }),+ KeyMap,+ WebClipNode+ ],+ onBeforeCreate: ({ editor }) => {+ editor.storage.portalProviderAPI = PortalProviderAPI;+ if (onBeforeCreate) onBeforeCreate({ editor });+ },+ injectCSS: false,+ parseOptions: { preserveWhitespace: true }+ } as EditorOptions),[onPreviewAttachment,onDownloadAttachment,