Skip to content

Commit 2012590

Browse files
committed
feat: add shortcutKeys override(s) to extensions
1 parent a30edfa commit 2012590

File tree

18 files changed

+38
-35
lines changed

18 files changed

+38
-35
lines changed

src/extensions/Blockquote/Blockquote.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export const Blockquote = /* @__PURE__ */ TiptapBlockquote.extend<BlockquoteOpti
1515
HTMLAttributes: {
1616
class: 'blockquote',
1717
},
18-
button: ({ editor, t }: any) => ({
18+
button: ({ editor, t, extension }: any) => ({
1919
component: ActionButton,
2020
componentProps: {
2121
action: () => editor.commands.toggleBlockquote(),
2222
isActive: () => editor.isActive('blockquote') || false,
2323
disabled: !editor.can().toggleBlockquote(),
2424
icon: 'TextQuote',
25-
shortcutKeys: ['shift', 'mod', 'B'],
25+
shortcutKeys: extension.options.shortcutKeys ?? ['shift', 'mod', 'B'],
2626
tooltip: t('editor.blockquote.tooltip'),
2727
},
2828
}),

src/extensions/Bold/Bold.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export const Bold = /* @__PURE__ */ TiptapBold.extend<BoldOptions>({
1010
addOptions() {
1111
return {
1212
...this.parent?.(),
13-
button: ({ editor, t }: any) => ({
13+
button: ({ editor, t, extension }: any) => ({
1414
component: ActionButton,
1515
componentProps: {
1616
action: () => editor.commands.toggleBold(),
1717
isActive: () => editor.isActive('bold') || false,
1818
disabled: false,
1919
icon: 'Bold',
20-
shortcutKeys: ['mod', 'B'],
20+
shortcutKeys: extension.options.shortcutKeys ?? ['mod', 'B'],
2121
tooltip: t('editor.bold.tooltip'),
2222
},
2323
}),

src/extensions/BulletList/BulletList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export const BulletList = /* @__PURE__ */ TiptapBulletList.extend<BulletListOpti
1212
addOptions() {
1313
return {
1414
...this.parent?.(),
15-
button: ({ editor, t }) => ({
15+
button: ({ editor, t, extension }) => ({
1616
component: ActionButton,
1717
componentProps: {
1818
action: () => editor.commands.toggleBulletList(),
1919
isActive: () => editor.isActive('bulletList') || false,
2020
disabled: false,
21-
shortcutKeys: ['shift', 'mod', '8'],
21+
shortcutKeys: extension.options.shortcutKeys ?? ['shift', 'mod', '8'],
2222
icon: 'List',
2323
tooltip: t('editor.bulletlist.tooltip'),
2424
},

src/extensions/Code/Code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export const Code = /* @__PURE__ */ TiptapCode.extend<CodeOptions>({
1010
addOptions() {
1111
return {
1212
...this.parent?.(),
13-
button: ({ editor, t }) => ({
13+
button: ({ editor, t, extension }) => ({
1414
component: ActionButton,
1515
componentProps: {
1616
action: () => editor.commands.toggleCode(),
1717
isActive: () => editor.isActive('code') || false,
1818
disabled: !editor.can().toggleCode(),
1919
icon: 'Code',
20-
shortcutKeys: ['mod', 'E'],
20+
shortcutKeys: extension.options.shortcutKeys ?? ['mod', 'E'],
2121
tooltip: t('editor.code.tooltip'),
2222
},
2323
}),

src/extensions/Heading/Heading.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const Heading = /* @__PURE__ */ TiptapHeading.extend<HeadingOptions>({
2727
disabled: !editor.can().toggleHeading({ level }),
2828
title: t(`editor.heading.h${level}.tooltip`),
2929
level,
30-
shortcutKeys: ['alt', 'mod', `${level}`],
30+
shortcutKeys: extension.options.shortcutKeys?.[level] ?? ['alt', 'mod', `${level}`],
3131
}));
3232

3333
if (baseKitExt && baseKitExt.options.paragraph !== false) {
@@ -37,7 +37,7 @@ export const Heading = /* @__PURE__ */ TiptapHeading.extend<HeadingOptions>({
3737
disabled: !editor.can().setParagraph(),
3838
level: 0,
3939
title: t('editor.paragraph.tooltip'),
40-
shortcutKeys: ['alt', 'mod', '0'],
40+
shortcutKeys: extension.options.shortcutKeys?.[0] ?? ['alt', 'mod', '0'],
4141
});
4242
}
4343

src/extensions/Highlight/Highlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const Highlight = /* @__PURE__ */ TiptapHighlight.extend<HighlightOptions
3131
editor,
3232
isActive: () => editor.isActive('highlight') || false,
3333
disabled: false,
34-
shortcutKeys: ['⇧', 'mod', 'H'],
34+
shortcutKeys: extension.options.shortcutKeys ?? ['⇧', 'mod', 'H'],
3535
tooltip: t('editor.highlight.tooltip'),
3636
defaultColor: extension.options.defaultColor
3737
},

src/extensions/History/History.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const History = /* @__PURE__ */ TiptapHistory.extend<HistoryOptions>({
1414
...this.parent?.(),
1515
depth: 100,
1616
newGroupDelay: 500,
17-
button: ({ editor, t }: any) => {
17+
button: ({ editor, t, extension }: any) => {
1818
return historys.map(item => ({
1919
component: HistoryActionButton,
2020
componentProps: {
@@ -26,7 +26,7 @@ export const History = /* @__PURE__ */ TiptapHistory.extend<HistoryOptions>({
2626
editor.chain().focus().redo().run();
2727
}
2828
},
29-
shortcutKeys: item === 'undo' ? ['mod', 'Z'] : ['shift', 'mod', 'Z'],
29+
shortcutKeys: item === 'undo' ? (extension.options.shortcutKeys?.[0] ?? ['mod', 'Z']) : (extension.options.shortcutKeys?.[1] ?? ['shift', 'mod', 'Z']),
3030
disabled: item === 'undo' ? !editor.can().undo() : !editor.can().redo(),
3131
isActive: () => (item === 'undo' ? !editor.can().undo() : !editor.can().redo()),
3232
icon: item === 'undo' ? 'Undo2' : 'Redo2',

src/extensions/HorizontalRule/HorizontalRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export const HorizontalRule = /* @__PURE__ */ TiptapHorizontalRule.extend<Horizo
2222
addOptions() {
2323
return {
2424
...this.parent?.(),
25-
button: ({ editor, t }) => ({
25+
button: ({ editor, t, extension }) => ({
2626
component: ActionButton,
2727
componentProps: {
2828
action: () => editor.commands.setHorizontalRule(),
2929
disabled: !editor.can().setHorizontalRule(),
3030
icon: 'Minus',
31-
shortcutKeys: ['mod', 'alt', 'S'],
31+
shortcutKeys: extension.options.shortcutKeys ?? ['mod', 'alt', 'S'],
3232
tooltip: t('editor.horizontalrule.tooltip'),
3333
},
3434
}),

src/extensions/ImportWord/ImportWord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const ImportWord = /* @__PURE__ */ Extension.create<ImportWordOptions>({
4040
action: () => editor.commands.setHorizontalRule(),
4141
disabled: !editor.can().setHorizontalRule(),
4242
icon: 'Word',
43-
shortcutKeys: ['alt', 'mod', 'S'],
43+
shortcutKeys: extension.options.shortcutKeys ?? ['alt', 'mod', 'S'],
4444
tooltip: t('editor.importWord.tooltip'),
4545
},
4646
};

src/extensions/Indent/Indent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ export const Indent = /* @__PURE__ */ Extension.create<IndentOptions>({
3434
types: ['paragraph', 'heading', 'blockquote'],
3535
minIndent: IndentProps.min,
3636
maxIndent: IndentProps.max,
37-
button({ editor, t }: { editor: Editor, t: (...args: any[]) => string }) {
37+
button({ editor, t, extension }) {
3838
return [
3939
{
4040
component: ActionButton,
4141
componentProps: {
4242
action: () => {
4343
editor.commands.indent();
4444
},
45-
shortcutKeys: ['Tab'],
45+
shortcutKeys: extension.options.shortcutKeys?.[0] ?? ['Tab'],
4646
icon: 'IndentIncrease',
4747
tooltip: t('editor.indent.tooltip'),
4848
},
@@ -53,7 +53,7 @@ export const Indent = /* @__PURE__ */ Extension.create<IndentOptions>({
5353
action: () => {
5454
editor.commands.outdent();
5555
},
56-
shortcutKeys: ['Shift', 'Tab'],
56+
shortcutKeys: extension.options.shortcutKeys?.[1] ?? ['Shift', 'Tab'],
5757
icon: 'IndentDecrease',
5858
tooltip: t('editor.outdent.tooltip'),
5959
},

0 commit comments

Comments
 (0)