Skip to content

Commit

Permalink
fix(strikethrough): update strikethrough shortcut (#4288)
Browse files Browse the repository at this point in the history
* update strikethrough shortcut
* update tests
  • Loading branch information
bdbch committed Aug 5, 2023
1 parent 4f4a389 commit fd35db4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions demos/src/Marks/Strike/React/index.spec.js
Expand Up @@ -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')
})
Expand Down
6 changes: 3 additions & 3 deletions demos/src/Marks/Strike/Vue/index.spec.js
Expand Up @@ -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')
})
Expand Down
11 changes: 9 additions & 2 deletions packages/extension-strike/src/strike.ts
@@ -1,4 +1,5 @@
import {
isMacOS,
Mark,
markInputRule,
markPasteRule,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit fd35db4

Please sign in to comment.