Skip to content

Commit

Permalink
Add removeHotkey to keyboard module, closes #110
Browse files Browse the repository at this point in the history
Takes a string, number, or hotkey object.
  • Loading branch information
thomsbg committed Aug 13, 2015
1 parent ad73e17 commit 3a7b4fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/modules/keyboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/unit/modules/keyboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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');
)
)
)

0 comments on commit 3a7b4fd

Please sign in to comment.