Skip to content

Commit

Permalink
Add key bindings for uppercase letters for bold, italic underline
Browse files Browse the repository at this point in the history
This way, key bindings 'Mod-B', 'Mod-I' and 'Mod-U' with active caps
lock have the same effect as their lowercase siblings.

This is supposed to be fixed in Tiptap v2 upstream:
ueberdosis/tiptap#2426
ueberdosis/tiptap#2478

Fixes: #2050

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Feb 3, 2022
1 parent f896e7e commit 68ff460
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/marks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from 'tiptap-extensions'
import { Plugin } from 'tiptap'
import { getMarkAttrs } from 'tiptap-utils'
import { markInputRule, markPasteRule } from 'tiptap-commands'
import { markInputRule, markPasteRule, toggleMark } from 'tiptap-commands'
import { domHref, parseHref } from './../helpers/links'
import markdownit from './../markdownit'

Expand All @@ -44,6 +44,14 @@ class Strong extends Bold {
return 'strong'
}

// TODO: remove once we upgraded to tiptap v2
keys({ type }) {
return {
'Mod-b': toggleMark(type),
'Mod-B': toggleMark(type),
}
}

// TODO: remove once we upgraded to tiptap v2
inputRules({ type }) {
return [
Expand All @@ -66,6 +74,14 @@ class Italic extends TipTapItalic {
return 'em'
}

// TODO: remove once we upgraded to tiptap v2
keys({ type }) {
return {
'Mod-i': toggleMark(type),
'Mod-I': toggleMark(type),
}
}

// TODO: remove once we upgraded to tiptap v2
inputRules({ type }) {
return [
Expand Down Expand Up @@ -113,6 +129,14 @@ class Strike extends TipTapStrike {
}
}

// TODO: remove once we upgraded to tiptap v2
keys({ type }) {
return {
'Mod-d': toggleMark(type),
'Mod-D': toggleMark(type),
}
}

// TODO: remove once we upgraded to tiptap v2
inputRules({ type }) {
return [
Expand Down Expand Up @@ -229,13 +253,19 @@ class Underline extends TipTapUnderline {
}

// TODO: remove once we upgraded to tiptap v2
keys({ type }) {
return {
'Mod-u': toggleMark(type),
'Mod-U': toggleMark(type),
}
}

inputRules({ type }) {
return [
markInputRule(/(?:^|\s)((?:__)((?:[^__]+))(?:__))$/, type),
]
}

// TODO: remove once we upgraded to tiptap v2
pasteRules({ type }) {
return [
markPasteRule(/(?:^|\s)((?:__)((?:[^__]+))(?:__))/g, type),
Expand Down

0 comments on commit 68ff460

Please sign in to comment.