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 authored and jhchen committed Nov 10, 2015
1 parent 1bd1b55 commit f67dd2b
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 f67dd2b

Please sign in to comment.