diff --git a/spec/tooltip-manager-spec.coffee b/spec/tooltip-manager-spec.coffee index 40ac6d746..75b15eb48 100644 --- a/spec/tooltip-manager-spec.coffee +++ b/spec/tooltip-manager-spec.coffee @@ -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" diff --git a/src/tooltip-manager.coffee b/src/tooltip-manager.coffee index ca7e81f05..129a41fc6 100644 --- a/src/tooltip-manager.coffee +++ b/src/tooltip-manager.coffee @@ -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)