 
   constructor: (@editor) ->
     @root = @editor.doc.root
+    @hotkeys = {}
+    this.initListeners()
+    this.initHotkeys()
+
+  initListeners: ->
     @root.addEventListener('keydown', (event) =>
       event ||= window.event
       if @hotkeys[event.which]?
         _.each(@hotkeys[event.which], (hotkey) ->
           return if hotkey.meta? and event.metaKey != hotkey.meta
           return if hotkey.shift? and event.shiftKey != hotkey.shift
-          hotkey.callback.call(null)
+          selection = @editor.getSelection()
+          return unless selection?
+          hotkey.callback.call(null, selection)
         )
         event.preventDefault()
         return false
       return true
     )
-    @hotkeys = {}
-    this.initHotkeys()
 
   initHotkeys: ->
     this.addHotkey(TandemKeyboard.KEYS.TAB, =>

      range = new Tandem.Range(@editor, index + text.length, index + text.length)
      @editor.setSelection(range)


window.Tandem ||= {}
window.Tandem.Keyboard = TandemKeyboard

      @editor.selection.deleteRange()
      this.insertText("\n")
    )
    this.addHotkey(TandemKeyboard.KEYS.BACKSPACE, (selection) =>
      unless @editor.selection.deleteRange()
        index = selection.start.getIndex()
        @editor.deleteAt(index - 1, 1) if index? && index > 0
    )
    this.addHotkey(TandemKeyboard.KEYS.DELETE, (selection) =>
      unless @editor.selection.deleteRange()
        index = selection.start.getIndex()
        @editor.deleteAt(index, 1) if index? && index < @editor.doc.length - 1
    )
    this.addHotkey(Tandem.Keyboard.HOTKEYS.BOLD, (selection) =>
      this.toggleAttribute(selection, 'bold')
    )
    this.addHotkey(Tandem.Keyboard.HOTKEYS.ITALIC, (selection) =>
      this.toggleAttribute(selection, 'italic')
    )
    this.addHotkey(Tandem.Keyboard.HOTKEYS.UNDERLINE, (selection) =>
      this.toggleAttribute(selection, 'underline')
    )

  addHotkey: (hotkey, callback) ->
