fix(strikethrough): update strikethrough shortcut (#4288)

* update strikethrough shortcut
* update tests
This commit is contained in:
bdbch 2023-08-05 11:38:35 +02:00 committed by GitHub
parent 4f4a389e00
commit fd35db4d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -58,15 +58,15 @@ context('/src/Marks/Strike/React/', () => {
it('should strike the selected text when the keyboard shortcut is pressed', () => {
cy.get('.tiptap')
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.find('s')
.should('contain', 'Example Text')
})
it('should toggle the selected text striked when the keyboard shortcut is pressed', () => {
cy.get('.tiptap')
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.find('s')
.should('not.exist')
})

View File

@ -64,15 +64,15 @@ context('/src/Marks/Strike/Vue/', () => {
it('should strike the selected text when the keyboard shortcut is pressed', () => {
cy.get('.tiptap')
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.find('s')
.should('contain', 'Example Text')
})
it('should toggle the selected text striked when the keyboard shortcut is pressed', () => {
cy.get('.tiptap')
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.trigger('keydown', { ctrlKey: true, shiftKey: true, key: 's' })
.find('s')
.should('not.exist')
})

View File

@ -1,4 +1,5 @@
import {
isMacOS,
Mark,
markInputRule,
markPasteRule,
@ -78,9 +79,15 @@ export const Strike = Mark.create<StrikeOptions>({
},
addKeyboardShortcuts() {
return {
'Mod-Shift-x': () => this.editor.commands.toggleStrike(),
const shortcuts: Record<string, () => boolean> = {}
if (isMacOS()) {
shortcuts['Mod-Shift-s'] = () => this.editor.commands.toggleStrike()
} else {
shortcuts['Ctrl-Shift-s'] = () => this.editor.commands.toggleStrike()
}
return shortcuts
},
addInputRules() {