Skip to content

Commit

Permalink
Add custom RichTextStrikethrough extension to restore the old shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral committed Aug 17, 2023
1 parent 3505904 commit 9fd1b15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/extensions/rich-text/rich-text-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ListItem } from '@tiptap/extension-list-item'
import { ListKeymap } from '@tiptap/extension-list-keymap'
import { OrderedList } from '@tiptap/extension-ordered-list'
import { Paragraph } from '@tiptap/extension-paragraph'
import { Strike } from '@tiptap/extension-strike'
import { Text } from '@tiptap/extension-text'
import { Typography } from '@tiptap/extension-typography'

Expand All @@ -31,6 +30,7 @@ import { RichTextDocument } from './rich-text-document'
import { RichTextHorizontalRule } from './rich-text-horizontal-rule'
import { RichTextImage } from './rich-text-image'
import { RichTextLink } from './rich-text-link'
import { RichTextStrikethrough, RichTextStrikethroughOptions } from './rich-text-strikethrough'

import type { Extensions } from '@tiptap/core'
import type { BlockquoteOptions } from '@tiptap/extension-blockquote'
Expand All @@ -47,7 +47,6 @@ import type { ListItemOptions } from '@tiptap/extension-list-item'
import type { ListKeymapOptions } from '@tiptap/extension-list-keymap'
import type { OrderedListOptions } from '@tiptap/extension-ordered-list'
import type { ParagraphOptions } from '@tiptap/extension-paragraph'
import type { StrikeOptions } from '@tiptap/extension-strike'
import type { RichTextDocumentOptions } from './rich-text-document'
import type { RichTextHorizontalRuleOptions } from './rich-text-horizontal-rule'
import type { RichTextImageOptions } from './rich-text-image'
Expand Down Expand Up @@ -175,7 +174,7 @@ type RichTextKitOptions = {
/**
* Set options for the `Strike` extension, or `false` to disable.
*/
strike: Partial<StrikeOptions> | false
strike: Partial<RichTextStrikethroughOptions> | false

/**
* Set to `false` to disable the `Text` extension.
Expand Down Expand Up @@ -319,7 +318,7 @@ const RichTextKit = Extension.create<RichTextKitOptions>({
}

if (this.options.strike !== false) {
extensions.push(Strike.configure(this.options?.strike))
extensions.push(RichTextStrikethrough.configure(this.options?.strike))
}

if (this.options.text !== false) {
Expand Down
18 changes: 18 additions & 0 deletions src/extensions/rich-text/rich-text-strikethrough.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Strike } from '@tiptap/extension-strike'

import type { StrikeOptions } from '@tiptap/extension-strike'

/**
* Custom extension that extends the built-in `Strike` extension to overwrite the default keyboard.
*/
const RichTextStrikethrough = Strike.extend({
addKeyboardShortcuts() {
return {
'Mod-Shift-x': () => this.editor.commands.toggleStrike(),
}
},
})

export { RichTextStrikethrough }

export type { StrikeOptions as RichTextStrikethroughOptions }

0 comments on commit 9fd1b15

Please sign in to comment.