diff --git a/src/modules/keyboard.coffee b/src/modules/keyboard.coffee index 568b3b9371..0beb684428 100644 --- a/src/modules/keyboard.coffee +++ b/src/modules/keyboard.coffee @@ -30,6 +30,13 @@ class Keyboard @hotkeys[which].push(hotkey) ) + removeHotkey: (hotkey) -> + hotkey = if Keyboard.hotkeys[hotkey] then Keyboard.hotkeys[hotkey] else hotkey + hotkey = if _.isObject(hotkey) then hotkey else { key: hotkey } + which = if _.isNumber(hotkey.key) then hotkey.key else hotkey.key.toUpperCase().charCodeAt(0) + for handler in @hotkeys[which] || [] + return handler.callback if _.isEqual(hotkey, _.omit(handler, 'callback')) + toggleFormat: (range, format) -> if range.isCollapsed() delta = @quill.getContents(Math.max(0, range.start-1), range.end) diff --git a/test/unit/modules/keyboard.coffee b/test/unit/modules/keyboard.coffee index 460d361533..66c0cb2e38 100644 --- a/test/unit/modules/keyboard.coffee +++ b/test/unit/modules/keyboard.coffee @@ -80,5 +80,20 @@ describe('Keyboard', -> expect(dom($('.ql-bold').get(0)).hasClass('ql-active')).toBe(true) expect(dom($('.ql-size').get(0)).value()).toBe(size) ) + + it('removeHotkey by name', -> + fn = @quill.getModule('keyboard').removeHotkey('BOLD') + expect(typeof fn).toBe('function'); + ) + + it('removeHotkey by number', -> + fn = @quill.getModule('keyboard').removeHotkey(13) + expect(typeof fn).toBe('function'); + ) + + it('removeHotkey by object', -> + fn = @quill.getModule('keyboard').removeHotkey({ key: 'B', metaKey: true }) + expect(typeof fn).toBe('function'); + ) ) )