Add support for keyBindingTarget to TooltipManager::add

This commit is contained in:
Nathan Sobo
2014-11-19 19:10:36 -07:00
parent 175d7811b4
commit 7bdf3b1719
2 changed files with 14 additions and 3 deletions

View File

@@ -34,8 +34,8 @@ describe "TooltipManager", ->
describe "when a title is specified", ->
it "appends the key binding corresponding to the command to the title", ->
atom.keymaps.add 'test',
'.bar': 'ctrl-x ctrl-z': 'test-command'
'.foo': 'ctrl-x ctrl-y': 'test-command'
'.bar': 'ctrl-x ctrl-z': 'test-command'
manager.add element, title: "Title", keyBindingCommand: 'test-command'
@@ -52,3 +52,15 @@ describe "TooltipManager", ->
hover element, ->
tooltipElement = document.body.querySelector(".tooltip")
expect(tooltipElement).toHaveText "⌃X ⌃Y"
describe "when a keyBindingTarget is specified", ->
it "looks up the key binding relative to the target", ->
atom.keymaps.add 'test',
'.bar': 'ctrl-x ctrl-z': 'test-command'
'.foo': 'ctrl-x ctrl-y': 'test-command'
manager.add element, keyBindingCommand: 'test-command', keyBindingTarget: element
hover element, ->
tooltipElement = document.body.querySelector(".tooltip")
expect(tooltipElement).toHaveText "⌃X ⌃Y"

View File

@@ -15,10 +15,9 @@ class TooltipManager
add: (target, options) ->
requireBootstrapTooltip()
{keyBindingCommand} = options
{keyBindingCommand, keyBindingTarget} = options
if keyBindingCommand?
keyBindingTarget = target unless typeof target is 'string'
bindings = atom.keymaps.findKeyBindings(command: keyBindingCommand, target: keyBindingTarget)
if options.title?
options.title += " " + getKeystroke(bindings)