Skip to content

Commit

Permalink
feat: add keyboard shortcut for clear formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslam97 committed Aug 11, 2024
1 parent fdac9fd commit ca5b8a7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/minimal-tiptap/components/section/two.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const formatActions: FormatAction[] = [
label: 'Clear formatting',
action: editor => editor.chain().focus().unsetAllMarks().run(),
isActive: () => false,
canExecute: editor => editor.can().chain().focus().unsetAllMarks().run() && !editor.isActive('codeBlock')
canExecute: editor => editor.can().chain().focus().unsetAllMarks().run() && !editor.isActive('codeBlock'),
shortcut: ['mod', '\\']
}
]

Expand Down
1 change: 1 addition & 0 deletions src/components/minimal-tiptap/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './horizontal-rule'
export * from './image'
export * from './link'
export * from './selection'
export * from './unset-all-marks'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './unset-all-marks'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Extension } from '@tiptap/core'

export const UnsetAllMarks = Extension.create({
addKeyboardShortcuts() {
return {
'Mod-\\': () => this.editor.commands.unsetAllMarks()
}
}
})
5 changes: 3 additions & 2 deletions src/components/minimal-tiptap/hooks/use-minimal-tiptap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Editor } from '@tiptap/core'
import { Typography } from '@tiptap/extension-typography'
import { Placeholder } from '@tiptap/extension-placeholder'
import { TextStyle } from '@tiptap/extension-text-style'
import { Link, Image, HorizontalRule, CodeBlockLowlight, Selection, Color } from '../extensions'
import { Link, Image, HorizontalRule, CodeBlockLowlight, Selection, Color, UnsetAllMarks } from '../extensions'
import { cn } from '@/lib/utils'
import { getOutput } from '../utils'
import { useThrottle } from '../hooks/use-throttle'
Expand Down Expand Up @@ -35,10 +35,11 @@ const createExtensions = (placeholder: string) => [
}),
Link,
Image,
TextStyle,
Color,
TextStyle,
Selection,
Typography,
UnsetAllMarks,
HorizontalRule,
CodeBlockLowlight,
Placeholder.configure({ placeholder: () => placeholder })
Expand Down

0 comments on commit ca5b8a7

Please sign in to comment.