diff --git a/package.json b/package.json index 04e4e3e0..e15703d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matters/matters-editor", - "version": "0.2.0-alpha.38", + "version": "0.2.0-alpha.39", "description": "Editor for matters.news", "author": "https://github.com/thematters", "homepage": "https://github.com/thematters/matters-editor", diff --git a/src/editors/extensions/figureAudio.ts b/src/editors/extensions/figureAudio.ts index c28284d8..e360f710 100644 --- a/src/editors/extensions/figureAudio.ts +++ b/src/editors/extensions/figureAudio.ts @@ -1,5 +1,6 @@ import { Node } from '@tiptap/core' import { Plugin, PluginKey } from '@tiptap/pm/state' +import { GapCursor } from '@tiptap/pm/gapcursor' /** * FigureAudio extension: @@ -168,13 +169,21 @@ export const FigureAudio = Node.create({ return } - // enter to insert a new paragraph + // set gapcursor to insert a new paragraph if (isEnter) { - editor - .chain() - .selectTextblockEnd() - .insertContent({ type: 'paragraph' }) - .run() + const { from, to } = editor.state.selection + const resolvedPos = editor.state.doc.resolve(from + 1) + + if (from !== to) { + return + } + + // @ts-ignore + if (GapCursor.valid(resolvedPos)) { + const selection = new GapCursor(resolvedPos) + view.dispatch(view.state.tr.setSelection(selection)) + } + return } }, diff --git a/src/editors/extensions/figureEmbed.ts b/src/editors/extensions/figureEmbed.ts index 40008d86..d784b4e7 100644 --- a/src/editors/extensions/figureEmbed.ts +++ b/src/editors/extensions/figureEmbed.ts @@ -1,5 +1,6 @@ import { Node } from '@tiptap/core' import { Plugin, PluginKey } from '@tiptap/pm/state' +import { GapCursor } from '@tiptap/pm/gapcursor' /** * FigureEmbed extension: @@ -352,13 +353,21 @@ export const FigureEmbed = Node.create({ return } - // enter to insert a new paragraph + // set gapcursor to insert a new paragraph if (isEnter) { - editor - .chain() - .selectTextblockEnd() - .insertContent({ type: 'paragraph' }) - .run() + const { from, to } = editor.state.selection + const resolvedPos = editor.state.doc.resolve(from + 1) + + if (from !== to) { + return + } + + // @ts-ignore + if (GapCursor.valid(resolvedPos)) { + const selection = new GapCursor(resolvedPos) + view.dispatch(view.state.tr.setSelection(selection)) + } + return } }, diff --git a/src/editors/extensions/figureImage.ts b/src/editors/extensions/figureImage.ts index d6a4a03e..bdd28f53 100644 --- a/src/editors/extensions/figureImage.ts +++ b/src/editors/extensions/figureImage.ts @@ -1,5 +1,6 @@ import { Node } from '@tiptap/core' import { Plugin, PluginKey } from '@tiptap/pm/state' +import { GapCursor } from '@tiptap/pm/gapcursor' /** * FigureImage extension: @@ -122,13 +123,21 @@ export const FigureImage = Node.create({ return } - // enter to insert a new paragraph + // set gapcursor to insert a new paragraph if (isEnter) { - editor - .chain() - .selectTextblockEnd() - .insertContent({ type: 'paragraph' }) - .run() + const { from, to } = editor.state.selection + const resolvedPos = editor.state.doc.resolve(from + 1) + + if (from !== to) { + return + } + + // @ts-ignore + if (GapCursor.valid(resolvedPos)) { + const selection = new GapCursor(resolvedPos) + view.dispatch(view.state.tr.setSelection(selection)) + } + return } },