From 68ff4601caef381148a847f7a4c6a253650c5344 Mon Sep 17 00:00:00 2001 From: Jonas Date: Thu, 3 Feb 2022 13:18:18 +0100 Subject: [PATCH] Add key bindings for uppercase letters for bold, italic underline 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: https://github.com/ueberdosis/tiptap/issues/2426 https://github.com/ueberdosis/tiptap/pull/2478 Fixes: #2050 Signed-off-by: Jonas --- src/marks/index.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/marks/index.js b/src/marks/index.js index 2c536b12c23..9f8de6f7d24 100644 --- a/src/marks/index.js +++ b/src/marks/index.js @@ -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' @@ -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 [ @@ -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 [ @@ -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 [ @@ -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),