Skip to content

Commit

Permalink
Merge pull request #512 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v0.3.0-alpha.4
  • Loading branch information
robertu7 authored Aug 8, 2024
2 parents 3087beb + 357dbe0 commit 87e6d80
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 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.3.0-alpha.3",
"version": "0.3.0-alpha.4",
"description": "Editor for matters.news",
"author": "https://github.com/thematters",
"homepage": "https://github.com/thematters/matters-editor",
Expand Down
48 changes: 0 additions & 48 deletions src/editors/extensions/figcaptionKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Decoration, DecorationSet } from '@tiptap/pm/view'
* FigcaptionKit extension works with FigureAudio,
* FigureEmbed and FigureImage extensions to:
* - limit figcaption length
* - handle enter key event to insert a new paragraph
* - handle backspace key event to remove the figcaption if it's empty
* - handle click event to select the figcaption
* - customize the empty node class and placeholder
*
Expand Down Expand Up @@ -48,52 +46,6 @@ export const makeFigcaptionEventHandlerPlugin = ({
// @see {@url https://discuss.prosemirror.net/t/prevent-nodeview-selection-on-click/3193}
return true
},
handleKeyDown(view, event) {
const isBackSpace = event.key.toLowerCase() === 'backspace'
const isEnter = event.key.toLowerCase() === 'enter'

if (!isBackSpace && !isEnter) {
return
}

const anchorParent = view.state.selection.$anchor.parent
const isFigureExtensions = supportedFigureExtensions.includes(
anchorParent.type.name,
)
const isEmptyFigcaption = anchorParent.content.size <= 0

if (!isFigureExtensions) {
return
}

// backSpace to remove if the figcaption is empty
if (isBackSpace && isEmptyFigcaption) {
// FIXME: setTimeOut to avoid repetitive deletion
setTimeout(() => {
editor.commands.deleteNode(pluginName)
})
return
}

// insert a new paragraph
if (isEnter) {
const { $from, $to } = editor.state.selection
const isTextAfter = $to.nodeAfter?.type?.name === 'text'

// skip if figcaption text is selected
// or has text after current selection
if ($from !== $to || isTextAfter) {
return
}

// FIXME: setTimeOut to avoid repetitive paragraph insertion
setTimeout(() => {
editor.commands.insertContentAt($to.pos + 1, {
type: 'paragraph',
})
})
}
},
},
})
}
Expand Down

0 comments on commit 87e6d80

Please sign in to comment.