From c6b8d539aafe471d44d6c0d3ac09b936cf22e1d0 Mon Sep 17 00:00:00 2001 From: Anton Khodakivskiy Date: Fri, 2 Aug 2013 02:14:22 +0300 Subject: [PATCH] Refactored commands related machinery --- extension/bootstrap.coffee | 1 + extension/locale/de/vimfx.properties | 2 +- extension/locale/el-GR/vimfx.properties | 2 +- extension/locale/en-US/vimfx.properties | 4 +- extension/locale/hu/vimfx.properties | 2 +- extension/locale/nl/vimfx.properties | 2 +- extension/locale/pl/vimfx.properties | 2 +- extension/locale/ru/vimfx.properties | 2 +- extension/locale/zh-CN/vimfx.properties | 2 +- extension/packages/commands.coffee | 178 +++++++++++++----------- extension/packages/help.coffee | 67 +++++---- extension/packages/prefs.coffee | 42 +----- extension/packages/vim.coffee | 30 +--- extension/resources/style.css | 20 ++- 14 files changed, 177 insertions(+), 179 deletions(-) diff --git a/extension/bootstrap.coffee b/extension/bootstrap.coffee index 5921bdc..632f956 100644 --- a/extension/bootstrap.coffee +++ b/extension/bootstrap.coffee @@ -25,6 +25,7 @@ do (global = this) -> packages[name] = scope.exports catch error dump("Failed to load #{ name }: #{ error }\n") + dump(error.stack) return packages[name] diff --git a/extension/locale/de/vimfx.properties b/extension/locale/de/vimfx.properties index e1a9482..3c93fd5 100644 --- a/extension/locale/de/vimfx.properties +++ b/extension/locale/de/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=URL der aktuellen Seite in die Zwischenablage kopieren help_command_reload=Seite aktualisieren help_command_reload_force=Seite inklusive aller Zusatzelemente aktualisieren (js, css, img) help_command_reload_all=Seiten aller Tabs aktualisieren -help_command_reload_all_foce=Seiten aller Tabs inklusive aller Zusatzelemente aktualisieren (js, css, img) +help_command_reload_all_force=Seiten aller Tabs inklusive aller Zusatzelemente aktualisieren (js, css, img) help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/locale/el-GR/vimfx.properties b/extension/locale/el-GR/vimfx.properties index e4bb058..3f7f70a 100644 --- a/extension/locale/el-GR/vimfx.properties +++ b/extension/locale/el-GR/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=Κάνε αντιγραφή τη διεύθυνση της σ help_command_reload=Ανανέωσε την σελίδα στην οποία βρίσκομαι help_command_reload_force=Ανανέωσε την σελίδα στην οποία βρίσκομαι και όλα τα στοιχεία της (js, css, img) help_command_reload_all=Ανανέωσες τις σελίδες σε όλες τις καρτέλες -help_command_reload_all_foce=Ανανέωσες τις σελίδες σε όλες τις καρτέλες συμπεριλαμβανομένων και των στοιχείων της (js, css, img) +help_command_reload_all_force=Ανανέωσες τις σελίδες σε όλες τις καρτέλες συμπεριλαμβανομένων και των στοιχείων της (js, css, img) help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/locale/en-US/vimfx.properties b/extension/locale/en-US/vimfx.properties index 8d56ae2..3fc794d 100644 --- a/extension/locale/en-US/vimfx.properties +++ b/extension/locale/en-US/vimfx.properties @@ -5,7 +5,7 @@ item_preference=Preferences item_help=Help item_blacklist_button_tooltip=Blacklist -help_section_url=Dealing with URLs +help_section_urls=Dealing with URLs help_command_focus=Focus the Address Bar help_command_paste=Navigate to the address in the clipboard help_command_paste_tab=Open new tab and navigate to the address in the clipboard @@ -15,7 +15,7 @@ help_command_yank=Copy current page link to the clipboard help_command_reload=Reload current page help_command_reload_force=Reload current page and all assets (js, css, img) help_command_reload_all=Reload pages in all tabs -help_command_reload_all_foce=Reload pages in all tabs including assets (js, css, img) +help_command_reload_all_force=Reload pages in all tabs including assets (js, css, img) help_command_stop=Stop loading current page help_command_stop_all=Stop loading pages in all tabs diff --git a/extension/locale/hu/vimfx.properties b/extension/locale/hu/vimfx.properties index bec8691..ee77635 100644 --- a/extension/locale/hu/vimfx.properties +++ b/extension/locale/hu/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=Aktuális oldal címének másolása vágólapra help_command_reload=Oldal újratöltése help_command_reload_force=Oldal újratöltése minden elemmel együtt (js, css, img) help_command_reload_all=Összes oldal újratöltése -help_command_reload_all_foce=Összes oldal újratöltése minden elemmel együtt (js, css, img) +help_command_reload_all_force=Összes oldal újratöltése minden elemmel együtt (js, css, img) help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/locale/nl/vimfx.properties b/extension/locale/nl/vimfx.properties index 7fd4691..3ebddd6 100644 --- a/extension/locale/nl/vimfx.properties +++ b/extension/locale/nl/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=Kopieer link van huidige pagina naar klembord help_command_reload=Herlaad huidige pagina help_command_reload_force=Herlaad huidige pagina inclusief javascript, css en plaatjes help_command_reload_all=Herlaad alle tabbladen -help_command_reload_all_foce=Herlaad alle tabbladen inclusief javascript, css en plaatjes. +help_command_reload_all_force=Herlaad alle tabbladen inclusief javascript, css en plaatjes. help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/locale/pl/vimfx.properties b/extension/locale/pl/vimfx.properties index d5141ad..b95a651 100644 --- a/extension/locale/pl/vimfx.properties +++ b/extension/locale/pl/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=Kopiuj adres bieżącej strony do schowka help_command_reload=Odśwież bieżącą stronę help_command_reload_force=Odśwież bieżącą stronę wraz z zasobami (js, css, img) help_command_reload_all=Odśwież strony we wszystkich kartach -help_command_reload_all_foce=Odśwież strony we wszystkich kartach wraz z zasobami (js, css, img) +help_command_reload_all_force=Odśwież strony we wszystkich kartach wraz z zasobami (js, css, img) help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/locale/ru/vimfx.properties b/extension/locale/ru/vimfx.properties index ff99a81..c707d0f 100644 --- a/extension/locale/ru/vimfx.properties +++ b/extension/locale/ru/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=Скопировать в буфер обмена адрес help_command_reload=Перезагрузить текущую страницу help_command_reload_force=Перезагрузить текущую страницу и все ресурсы (js, css, img) help_command_reload_all=Перезагрузить страницы во всех вкладках -help_command_reload_all_foce=Перезагрузить страницы и ресурамы (js, css, img) во всех вкладках +help_command_reload_all_force=Перезагрузить страницы и ресурамы (js, css, img) во всех вкладках help_command_stop=Остановить загрузку help_command_stop_all=Остановить загрузку во всех вкладках diff --git a/extension/locale/zh-CN/vimfx.properties b/extension/locale/zh-CN/vimfx.properties index 6304628..d088364 100644 --- a/extension/locale/zh-CN/vimfx.properties +++ b/extension/locale/zh-CN/vimfx.properties @@ -15,7 +15,7 @@ help_command_yank=复制当前标签页链接到剪贴板 help_command_reload=重新载入当前页面 help_command_reload_force=重新载入当前页面及所有外部资源(js,css,img) help_command_reload_all=重新载入所有标签页中打开的页面 -help_command_reload_all_foce=重新载入所有标签页中包含外部资源(js,css,img)的页面 +help_command_reload_all_force=重新载入所有标签页中包含外部资源(js,css,img)的页面 help_command_stop=Stop loading current page (needs translation) help_command_stop_all=Stop loading pages in all tabs (needs translation) diff --git a/extension/packages/commands.coffee b/extension/packages/commands.coffee index 53b3c9f..64f3ec4 100644 --- a/extension/packages/commands.coffee +++ b/extension/packages/commands.coffee @@ -88,7 +88,7 @@ command_reload_all = (vim) -> window.location.reload(false) # Reload the page from the server -command_reload_all_foce = (vim) -> +command_reload_all_force = (vim) -> if rootWindow = utils.getRootWindow(vim.window) if tabs = rootWindow.gBrowser.tabContainer for i in [0...tabs.itemCount] @@ -238,7 +238,7 @@ command_tab_move_right = (vim) -> # Display the Help Dialog command_help = (vim) -> - help.injectHelp(vim.window.document, commandsHelp) + help.injectHelp(vim.window.document, commands) # Switch into find mode command_find = (vim) -> @@ -290,80 +290,86 @@ command_Esc = (vim) -> if chromeWindow = utils.getRootWindow(vim.window) chromeWindow.DeveloperToolbar.hide() -commandGroups = - 'urls': - 'o': [ command_focus, _('help_command_focus') ] - 'p': [ command_paste, _('help_command_paste') ] - 'P': [ command_paste_tab, _('help_command_paste_tab') ] - 'y,f': [ command_marker_yank, _('help_command_marker_yank') ] - 'v,f': [ command_marker_focus, _('help_command_marker_focus') ] - 'y,y': [ command_yank, _('help_command_yank') ] - 'r': [ command_reload, _('help_command_reload') ] - 'R': [ command_reload_force, _('help_command_reload_force') ] - 'a,r': [ command_reload_all, _('help_command_reload_all') ] - 'a,R': [ command_reload_all_foce, _('help_command_reload_all_foce') ] - 's': [ command_stop, _('help_command_stop') ] - 'a,s': [ command_stop_all, _('help_command_stop_all') ] - 'nav': - 'g,g': [ command_scroll_to_top , _('help_command_scroll_to_top') ] - 'G': [ command_scroll_to_bottom, _('help_command_scroll_to_bottom') ] - 'j|c-e': [ command_scroll_down, _('help_command_scroll_down') ] - 'k|c-y': [ command_scroll_up, _('help_command_scroll_up') ] - 'h': [ command_scroll_left, _('help_command_scroll_left') ] - 'l': [ command_scroll_right , _('help_command_scroll_right') ] - # Can't use c-u/c-d because c-u is widely used for viewing sources - 'd': [ command_scroll_half_page_down, _('help_command_scroll_half_page_down') ] - 'u': [ command_scroll_half_page_up, _('help_command_scroll_half_page_up') ] - 'c-f': [ command_scroll_page_down, _('help_command_scroll_page_down') ] - 'c-b': [ command_scroll_page_up, _('help_command_scroll_page_up') ] - 'tabs': - 't': [ command_open_tab, _('help_command_open_tab') ] - 'J|g,T': [ command_tab_prev, _('help_command_tab_prev') ] - 'K|g,t': [ command_tab_next, _('help_command_tab_next') ] - 'c-J': [ command_tab_move_left, _('help_command_tab_move_left') ] - 'c-K': [ command_tab_move_right, _('help_command_tab_move_right') ] - 'g,h': [ command_home, _('help_command_home') ] - 'g,H|g,\^': [ command_tab_first, _('help_command_tab_first') ] - 'g,L|g,$': [ command_tab_last, _('help_command_tab_last') ] - 'x': [ command_close_tab, _('help_command_close_tab') ] - 'X': [ command_reload_tab, _('help_command_reload_tab') ] - 'browse': - 'f': [ command_follow, _('help_command_follow') ] - 'F': [ command_follow_in_tab, _('help_command_follow_in_tab') ] - 'H': [ command_back, _('help_command_back') ] - 'L': [ command_forward, _('help_command_forward') ] - 'misc': - # `.` is added to find command mapping to hack around Russian keyboard layout - '\.|/': [ command_find, _('help_command_find') ] - 'a,\.|a,/': [ command_find_hl, _('help_command_find_hl') ] - 'n': [ command_find_next, _('help_command_find_next') ] - 'N': [ command_find_prev, _('help_command_find_prev') ] - # `>` is added to help command mapping to hack around Russian keyboard layout - # See key-utils.coffee for more info - '?|>': [ command_help, _('help_command_help') ] - 'Esc': [ command_Esc, _('help_command_Esc') ] - ':': [ command_dev, _('help_command_dev') ] - -# Merge groups and split command pipes into individual commands -commands = do (commandGroups) -> - newCommands = {} - for group, commandsList of commandGroups - for keys, command of commandsList - for key in keys.split('|') - newCommands[key] = command[0] - - return newCommands - -# Extract the help text from the commands preserving groups formation -commandsHelp = do (commandGroups) -> - helpStrings = {} - for group, commandsList of commandGroups - helpGroup = {} - for keys, command of commandsList - helpGroup[keys] = command[1] - - helpStrings[group] = helpGroup - return helpStrings +class Command + constructor: (@group, @name, @func, @keys) -> + @defaultKeys = @keys + try + @keys = JSON.parse(getPref(@prefName('keys'))) + catch err + @keys = @defaultKeys + + # Check if this command may match given string if more chars are added + mayMatch: (value) -> + return @keys.reduce(((m, v) -> m or v.indexOf(value) == 0), false) + + # Check is this command matches given string + match: (value) -> + return @keys.reduce(((m, v) -> m or v == value), false) + + # Name of the preference for a given property + prefName: (value) -> "commands.#{ @name }.#{ value }" + + assign: (value) -> + @keys = value or @defaultKeys + setPref(@prefName('keys'), value and JSON.stringify(value)) + + enabled: (value) -> + if value is undefined + return getPref(@prefName('enabled'), true) + else + setPref(@prefName('enabled'), !!value) + + help: -> _("help_command_#{ @name }") + +commands = [ + new Command('urls', 'focus', command_focus, ['o']) + new Command('urls', 'paste', command_paste, ['p']) + new Command('urls', 'paste_tab', command_paste_tab, ['P']) + new Command('urls', 'marker_yank', command_marker_yank, ['y,f']) + new Command('urls', 'marker_focus', command_marker_focus, ['v,f']) + new Command('urls', 'yank', command_yank, ['y,y']) + new Command('urls', 'reload', command_reload, ['r']) + new Command('urls', 'reload_force', command_reload_force, ['R']) + new Command('urls', 'reload_all', command_reload_all, ['a,r']) + new Command('urls', 'reload_all_force', command_reload_all_force, ['a,R']) + new Command('urls', 'stop', command_stop, ['s']) + new Command('urls', 'stop_all', command_stop_all, ['a,s']) + + new Command('nav', 'scroll_to_top', command_scroll_to_top , ['g,g']) + new Command('nav', 'scroll_to_bottom', command_scroll_to_bottom, ['G']) + new Command('nav', 'scroll_down', command_scroll_down, ['j', 'c-e']) + new Command('nav', 'scroll_up', command_scroll_up, ['k', 'c-y']) + new Command('nav', 'scroll_left', command_scroll_left, ['h']) + new Command('nav', 'scroll_right ', command_scroll_right , ['l']) + new Command('nav', 'scroll_half_page_down', command_scroll_half_page_down, ['d']) + new Command('nav', 'scroll_half_page_up', command_scroll_half_page_up, ['u']) + new Command('nav', 'scroll_page_down', command_scroll_page_down, ['c-f']) + new Command('nav', 'scroll_page_up', command_scroll_page_up, ['c-b']) + + new Command('tabs', 'open_tab', command_open_tab, ['t']) + new Command('tabs', 'tab_prev', command_tab_prev, ['J', 'g,T']) + new Command('tabs', 'tab_next', command_tab_next, ['K', 'g,t']) + new Command('tabs', 'tab_move_left', command_tab_move_left, ['c-J']) + new Command('tabs', 'tab_move_right', command_tab_move_right, ['c-K']) + new Command('tabs', 'home', command_home, ['g,h']) + new Command('tabs', 'tab_first', command_tab_first, ['g,H', 'g,\^']) + new Command('tabs', 'tab_last', command_tab_last, ['g,L', 'g,$']) + new Command('tabs', 'close_tab', command_close_tab, ['x']) + new Command('tabs', 'reload_tab', command_reload_tab, ['X']) + + new Command('browse', 'follow', command_follow, ['f']) + new Command('browse', 'follow_in_tab', command_follow_in_tab, ['F']) + new Command('browse', 'back', command_back, ['H']) + new Command('browse', 'forward', command_forward, ['L']) + + new Command('misc', 'find', command_find, ['\.', '/']) + new Command('misc', 'find_hl', command_find_hl, ['a,\.', 'a,/']) + new Command('misc', 'find_next', command_find_next, ['n']) + new Command('misc', 'find_prev', command_find_prev, ['N']) + new Command('misc', 'help', command_help, ['?', '>']) + new Command('misc', 'Esc', command_Esc, ['Esc']) + new Command('misc', 'dev', command_dev, [':']) +] # Called in hints mode. Will process the char, update and hide/show markers hintCharHandler = (vim, keyStr, charCode) -> @@ -384,6 +390,22 @@ hintCharHandler = (vim, keyStr, charCode) -> vim.enterNormalMode() break +findCommand = (keys) -> + for i in [0...keys.length] + str = keys[i..].join(',') + for cmd in commands + for key in cmd.keys + if key == str and cmd.enabled() + return cmd + +maybeCommand = (keys) -> + for i in [0...keys.length] + str = keys[i..].join(',') + for cmd in commands + for key in cmd.keys + if key.indexOf(str) == 0 and cmd.enabled() + return true + exports.hintCharHandler = hintCharHandler -exports.commands = commands -exports.commandsHelp = commandsHelp +exports.findCommand = findCommand +exports.maybeCommand = maybeCommand diff --git a/extension/packages/help.coffee b/extension/packages/help.coffee index e62c1f5..5451259 100644 --- a/extension/packages/help.coffee +++ b/extension/packages/help.coffee @@ -8,7 +8,7 @@ removeHelp = (document) -> if div = document.getElementById(CONTAINER_ID) div.parentNode.removeChild(div) -injectHelp = (document, commandsHelp) -> +injectHelp = (document, commands) -> if document.documentElement if div = document.getElementById(CONTAINER_ID) div.parentNode.removeChild(div) @@ -16,11 +16,11 @@ injectHelp = (document, commandsHelp) -> div.id = CONTAINER_ID div.className = 'VimFxReset' - div.appendChild(utils.parseHTML(document, helpDialogHtml(commandsHelp))) + div.appendChild(utils.parseHTML(document, helpDialogHtml(commands))) document.documentElement.appendChild(div) - installCheckboxHandlers(document) + installHandlers(document, commands) if button = document.getElementById('VimFxClose') clickHandler = (event) -> @@ -29,36 +29,51 @@ injectHelp = (document, commandsHelp) -> removeHelp(document) button.addEventListener('click', clickHandler, false) -installCheckboxHandlers = (document) -> - cbs = document.getElementsByClassName('VimFxKeyCheckbox') - for cb in cbs - cb.addEventListener 'change', (event)-> - key = event.target.getAttribute('data-key') +installHandlers = (document, commands) -> + changeHandler = (event) -> + name = event.target.getAttribute('data-name') + cmd = commands.reduce(((m, v) -> if (v.name == name) then v else m), null) + cmd.enabled(event.target.checked) + + for cb in document.getElementsByClassName('VimFxKeyCheckbox') + cb.addEventListener('change', changeHandler, false) + + clickHandler = (event) -> + event.preventDefault() + event.stopPropagation() + name = event.target.getAttribute('data-name') + cmd = commands.reduce(((m, v) -> if (v.name == name) then v else m), null) + console.log cmd.name + + for a in document.getElementsByClassName('VimFxKeyLink') + a.addEventListener('click', clickHandler, false) - # Checkbox if checked => command is in use - if event.target.checked - prefs.enableCommand(key) - else - prefs.disableCommand(key) td = (text, klass='') -> """#{ text }""" -tr = (key, text) -> - disabled = prefs.isCommandDisabled(key) - checked = if disabled then null else 'checked' +hint = (cmd, key) -> + keyDisplay = key.replace(/,/g, '') + """ + #{ keyDisplay } + """ + +tr = (cmd) -> + checked = if cmd.enabled() then 'checked' else null + keyData = cmd.defaultKeys.join('|') + hints = (hint(cmd, key) for key in cmd.keys).join('') key = """ - #{ key.replace(/,/g, '').replace('|', ', ') } + #{ hints } - + """ - return """#{ td(key, 'VimFxSequence') }#{ td(text) }""" + return """#{ td(key, 'VimFxSequence') }#{ td(cmd.help()) }""" table = (commands) -> """ - #{ (tr(cmd, text) for cmd, text of commands).join('') } + #{ (tr(cmd) for cmd in commands).join('') }
""" @@ -68,7 +83,7 @@ section = (title, commands) -> #{ table(commands) } """ -helpDialogHtml = (help) -> +helpDialogHtml = (commands) -> return """
@@ -83,13 +98,13 @@ helpDialogHtml = (help) ->
- #{ section(_('help_section_urls'), help['urls']) } - #{ section(_('help_section_nav'), help['nav']) } + #{ section(_('help_section_urls'), commands.filter((a) -> a.group == 'urls')) } + #{ section(_('help_section_nav'), commands.filter((a) -> a.group == 'nav')) }
- #{ section(_('help_section_tabs'), help['tabs']) } - #{ section(_('help_section_browse'), help['browse']) } - #{ section(_('help_section_misc'), help['misc']) } + #{ section(_('help_section_tabs'), commands.filter((a) -> a.group == 'tabs')) } + #{ section(_('help_section_browse'), commands.filter((a) -> a.group == 'browse')) } + #{ section(_('help_section_misc'), commands.filter((a) -> a.group == 'misc')) }
diff --git a/extension/packages/prefs.coffee b/extension/packages/prefs.coffee index 3ebb231..164bec7 100644 --- a/extension/packages/prefs.coffee +++ b/extension/packages/prefs.coffee @@ -1,5 +1,7 @@ { classes: Cc, interfaces: Ci } = Components +{ unload } = require 'unload' + PREF_BRANCH = 'extensions.VimFx.' # Default values for the preference @@ -71,43 +73,6 @@ setPref = do -> else branch.clearUserPref(key) -DISABLED_COMMANDS = do -> - str = getPref('disabled_commands') - try - return JSON.parse(str) - catch err - dc = [] - try - for key in str.split('||') - for c in key.split('|') - dc.push(c) if c - - return dc - -# Enables command -enableCommand = (key) -> - for c in key.split('|') - while (idx = DISABLED_COMMANDS.indexOf(c)) > -1 - DISABLED_COMMANDS.splice(idx, 1) - - setPref('disabled_commands', JSON.stringify(DISABLED_COMMANDS)) - -# Adds command to the disabled list -disableCommand = (key) -> - for c in key.split('|') - if DISABLED_COMMANDS.indexOf(c) == -1 - DISABLED_COMMANDS.push(c) - - setPref('disabled_commands', JSON.stringify(DISABLED_COMMANDS)) - -# Checks if given command is disabled in the preferences -isCommandDisabled = (key) -> - for c in key.split('|') - if DISABLED_COMMANDS.indexOf(c) > -1 - return true - - return false - initPrefValues = -> for key, value of DEFAULT_PREF_VALUES if not isPrefSet(key) @@ -118,7 +83,4 @@ exports.getPref = getPref exports.getDefaultPref = getDefaultPref exports.getFirefoxPref = getFirefoxPref exports.setPref = setPref -exports.isCommandDisabled = isCommandDisabled -exports.disableCommand = disableCommand -exports.enableCommand = enableCommand exports.initPrefValues = initPrefValues diff --git a/extension/packages/vim.coffee b/extension/packages/vim.coffee index 0e8f460..8926e31 100644 --- a/extension/packages/vim.coffee +++ b/extension/packages/vim.coffee @@ -1,8 +1,6 @@ utils = require 'utils' -{ commands -, hintCharHandler -} = require 'commands' +commands = require 'commands' { getPref , isCommandDisabled @@ -38,7 +36,7 @@ class Vim handleKeyDown: (keyboardEvent, keyStr) -> if @mode == MODE_NORMAL || keyStr == 'Esc' - result = maybeCommand(@keys.concat([keyStr])) + result = commands.maybeCommand(@keys.concat([keyStr])) else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey if @mode == MODE_HINTS result = utils.getHintChars().search(utils.regexpEscape(keyStr)) > -1 @@ -52,34 +50,16 @@ class Vim handleKeyPress: (keyboardEvent) -> lastKeyStr = if @keys.length > 0 then @keys[@keys.length - 1] else undefined if @mode == MODE_NORMAL or lastKeyStr == 'Esc' - if command = findCommand(@keys) - command(@) + if command = commands.findCommand(@keys) + command.func(@) @keys.length = 0 result = true else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey @keys.length = 0 if @mode == MODE_HINTS - hintCharHandler(@, lastKeyStr, keyboardEvent.charCode) + commands.hintCharHandler(@, lastKeyStr, keyboardEvent.charCode) result = true return result -findCommand = (keys) -> - for i in [0...keys.length] - seq = keys[i..].join(',') - if com = commands[seq] - if not isCommandDisabled(seq) - return com - - return undefined - -maybeCommand = (keys) -> - for i in [0...keys.length] - sequence = keys[i..].join(',') - for seq, com of commands - if seq.indexOf(sequence) == 0 - return not isCommandDisabled(seq) - - return false - exports.Vim = Vim diff --git a/extension/resources/style.css b/extension/resources/style.css index 8bb9542..20799e3 100644 --- a/extension/resources/style.css +++ b/extension/resources/style.css @@ -45,6 +45,23 @@ input.VimFxNotFound#VimFxFindInput { color: red; } +a.VimFxKeyLink { + display: inline; + background: #777; + border: none; + color: #fff; + cursor: pointer; + font-weight: bold; + border-radius: 3px; + text-shadow: 1px 1px #666; + font-size: 75%; + padding: 2px 3px; + margin: 0px 3px; +} +a.VimFxKeyLink:hover { + background-position: 0 -50px; +} + input#VimFxFindInput { position: fixed; bottom: 2px; @@ -192,7 +209,8 @@ div#VimFxHelpDialog td.VimFxReset { } div#VimFxHelpDialog td.VimFxSequence { - min-width:50px; + white-space: nowrap; + min-width:60px; text-align: right; padding-right:5px; font-weight:bold; -- 2.39.3