mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Replace keystrokes in tooltips
This commit is contained in:
@@ -22,9 +22,39 @@ tooltipDefaults =
|
||||
container: 'body'
|
||||
html: true
|
||||
|
||||
modifiers =
|
||||
cmd: '⌘'
|
||||
option: '⌥'
|
||||
ctrl: '⌃'
|
||||
shift: '⇧'
|
||||
left: '←'
|
||||
right: '→'
|
||||
up: '↑'
|
||||
down: '↓'
|
||||
|
||||
replaceKey = (key) ->
|
||||
if modifiers[key]
|
||||
modifiers[key]
|
||||
else if key.length == 1 and key == key.toUpperCase() and key.toUpperCase() != key.toLowerCase()
|
||||
[modifiers.shift, key.toUpperCase()]
|
||||
else if key.length == 1
|
||||
key.toUpperCase()
|
||||
else
|
||||
key
|
||||
|
||||
replaceModifiersInSingleKeystroke = (keystroke) ->
|
||||
keys = keystroke.split('-')
|
||||
keys = _.flatten(replaceKey(key) for key in keys)
|
||||
keys.join('')
|
||||
|
||||
replaceModifiers = (keystroke) ->
|
||||
keystrokes = keystroke.split(' ')
|
||||
keystrokes = (replaceModifiersInSingleKeystroke(stroke) for stroke in keystrokes)
|
||||
keystrokes.join(' ')
|
||||
|
||||
getKeystroke = (bindings) ->
|
||||
if bindings?.length
|
||||
"<span class=\"keystroke\">#{bindings[0].keystroke}</span>"
|
||||
"<span class=\"keystroke\">#{replaceModifiers(bindings[0].keystroke)}</span>"
|
||||
else
|
||||
''
|
||||
|
||||
@@ -38,4 +68,7 @@ jQuery.fn.setTooltip = (title, {command, commandElement}={}) ->
|
||||
|
||||
this.tooltip(jQuery.extend(tooltipDefaults, {title: "#{title} #{getKeystroke(bindings)}"}))
|
||||
|
||||
jQuery.fn.setTooltip.getKeystroke = getKeystroke
|
||||
jQuery.fn.setTooltip.replaceModifiers = replaceModifiers
|
||||
|
||||
module.exports = spacePen
|
||||
|
||||
Reference in New Issue
Block a user