mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-05 18:14:01 +08:00
b9bd469645
This way, key bindings 'Mod-B', 'Mod-I' and 'Mod-U' with active caps lock have the same effect as their lowercase siblings. Prosemirror examples did the same, see ProseMirror/prosemirror#895 Fixes: #2426 Signed-off-by: Jonas <jonas@freesources.org>
73 lines
1.5 KiB
TypeScript
73 lines
1.5 KiB
TypeScript
import { Mark, mergeAttributes } from '@tiptap/core'
|
|
|
|
export interface UnderlineOptions {
|
|
HTMLAttributes: Record<string, any>,
|
|
}
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands<ReturnType> {
|
|
underline: {
|
|
/**
|
|
* Set an underline mark
|
|
*/
|
|
setUnderline: () => ReturnType,
|
|
/**
|
|
* Toggle an underline mark
|
|
*/
|
|
toggleUnderline: () => ReturnType,
|
|
/**
|
|
* Unset an underline mark
|
|
*/
|
|
unsetUnderline: () => ReturnType,
|
|
}
|
|
}
|
|
}
|
|
|
|
export const Underline = Mark.create<UnderlineOptions>({
|
|
name: 'underline',
|
|
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
}
|
|
},
|
|
|
|
parseHTML() {
|
|
return [
|
|
{
|
|
tag: 'u',
|
|
},
|
|
{
|
|
style: 'text-decoration',
|
|
consuming: false,
|
|
getAttrs: style => ((style as string).includes('underline') ? {} : false),
|
|
},
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['u', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
setUnderline: () => ({ commands }) => {
|
|
return commands.setMark(this.name)
|
|
},
|
|
toggleUnderline: () => ({ commands }) => {
|
|
return commands.toggleMark(this.name)
|
|
},
|
|
unsetUnderline: () => ({ commands }) => {
|
|
return commands.unsetMark(this.name)
|
|
},
|
|
}
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-u': () => this.editor.commands.toggleUnderline(),
|
|
'Mod-U': () => this.editor.commands.toggleUnderline(),
|
|
}
|
|
},
|
|
})
|