Skip to content

Commit

Permalink
fix: insert new line behavior on figcaption
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed May 8, 2023
1 parent fd940c6 commit 590697c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 15 additions & 6 deletions src/editors/extensions/figureAudio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Node } from '@tiptap/core'
import { Plugin, PluginKey } from '@tiptap/pm/state'
import { GapCursor } from '@tiptap/pm/gapcursor'

/**
* FigureAudio extension:
Expand Down Expand Up @@ -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
}
},
Expand Down
21 changes: 15 additions & 6 deletions src/editors/extensions/figureEmbed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Node } from '@tiptap/core'
import { Plugin, PluginKey } from '@tiptap/pm/state'
import { GapCursor } from '@tiptap/pm/gapcursor'

/**
* FigureEmbed extension:
Expand Down Expand Up @@ -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
}
},
Expand Down
21 changes: 15 additions & 6 deletions src/editors/extensions/figureImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Node } from '@tiptap/core'
import { Plugin, PluginKey } from '@tiptap/pm/state'
import { GapCursor } from '@tiptap/pm/gapcursor'

/**
* FigureImage extension:
Expand Down Expand Up @@ -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
}
},
Expand Down

0 comments on commit 590697c

Please sign in to comment.