From 0047edaa505428942e8bb9926cfb6f933dad4b52 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 7 Sep 2013 04:09:23 +0200 Subject: [PATCH] Add command: Enter insert mode --- extension/locale/de/vimfx.properties | 2 ++ extension/locale/el-GR/vimfx.properties | 2 ++ extension/locale/en-US/vimfx.properties | 2 ++ extension/locale/hu/vimfx.properties | 2 ++ extension/locale/id/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/button.coffee | 34 +++++++++++++++---------- extension/packages/commands.coffee | 11 ++++---- extension/packages/modes.coffee | 14 +++++++++- extension/packages/utils.coffee | 9 +++++++ 13 files changed, 66 insertions(+), 20 deletions(-) diff --git a/extension/locale/de/vimfx.properties b/extension/locale/de/vimfx.properties index 91b795b..118d72b 100644 --- a/extension/locale/de/vimfx.properties +++ b/extension/locale/de/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx ist aktiviert. Zum Deaktivieren hier klicken. (Shift+Alt+V) button_tooltip_disabled=VimFx ist deaktiviert. Zum Aktivieren hier klicken. (Shift+Alt+V) button_tooltip_blacklisted=Diese Seite ist auf der schwarzen Liste +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Einstellungen item_help=Hilfe item_blacklist_button_tooltip=Schwarze Liste @@ -58,6 +59,7 @@ help_command_find=Suchmodus aktivieren help_command_find_hl=Suchmodus aktivieren und alle Übereinstimmungen markieren help_command_find_next=Zur nächsten Übereinstimmung springen help_command_find_prev=Zur vorherigen Übereinstimmung springen +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Entwickler-Werkzeuge öffnen help=Hilfe diff --git a/extension/locale/el-GR/vimfx.properties b/extension/locale/el-GR/vimfx.properties index e9695d6..7038efd 100644 --- a/extension/locale/el-GR/vimfx.properties +++ b/extension/locale/el-GR/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=Το VimFx είναι ενεργοποιημένο. Κάντε κλικ για να το απενεργοποιήσετε (Shift+Alt+V) button_tooltip_disabled=Το VimFx είναι απενεργοποιημένο. Κάντε κλικ για να το ενεργοποιήσετε (Shift+Alt+V) button_tooltip_blacklisted=Το VimFx είναι στην μαύρη λίστα σε αυτήν την σελίδα. +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Προτιμήσεις item_help=Βοήθεια item_blacklist_button_tooltip=Μαύρη Λίστα @@ -59,6 +60,7 @@ help_command_find=Είσοδος σε λειτουργία Εύρεσης (Find help_command_find_hl=Είσοδος σε λειτουργία Εύρεσης (Find mode) επισημαίνοντας όλες τις αντιστοιχίες help_command_find_next=Πήγαινε στην επόμενη ατιστοιχία help_command_find_prev=Πήγαινε στην προηγούμενη αντιστοιχία +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Άνοιγμα Developer Toolbar help=Βοήθεια diff --git a/extension/locale/en-US/vimfx.properties b/extension/locale/en-US/vimfx.properties index 4296146..08e259b 100644 --- a/extension/locale/en-US/vimfx.properties +++ b/extension/locale/en-US/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx is Enabled. Click to Disable (Shift+Alt+V) button_tooltip_disabled=VimFx is Disabled. Click to Enable (Shift+Alt+V) button_tooltip_blacklisted=VimFx is Blacklisted on this Page +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Preferences item_help=Help item_blacklist_button_tooltip=Blacklist @@ -59,6 +60,7 @@ help_command_find=Enter Find mode help_command_find_hl=Enter Find mode highlighting all matches help_command_find_next=Go to the next Find match help_command_find_prev=Go to the previous Find match +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Open Developer Toolbar help=Help diff --git a/extension/locale/hu/vimfx.properties b/extension/locale/hu/vimfx.properties index 8de7554..3d8525b 100644 --- a/extension/locale/hu/vimfx.properties +++ b/extension/locale/hu/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx aktív. Kattints az inaktiváláshoz (Shift+Alt+V) button_tooltip_disabled=VimFx inaktív. Kattints az aktiváláshoz (Shift+Alt+V) button_tooltip_blacklisted=Az oldal feketelistázva a VimFX-ben. +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Beállítások item_help=Súgó item_blacklist_button_tooltip=Feketelista @@ -58,6 +59,7 @@ help_command_find=Keresési módba lépés help_command_find_hl=Enter Find mode highlighting all matches (needs translation) help_command_find_next=Következő találatra ugrás help_command_find_prev=Előző találatra ugrás +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Open Developer Toolbar(needs translation) help=Segítség diff --git a/extension/locale/id/vimfx.properties b/extension/locale/id/vimfx.properties index 56c0c80..60175e1 100644 --- a/extension/locale/id/vimfx.properties +++ b/extension/locale/id/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx telah Aktif. Klik untuk Nonaktifkan (Shift+Alt+V) button_tooltip_disabled=VimFx telah Nonaktif. Klik untuk Aktifkan (Shift+Alt+V) button_tooltip_blacklisted=VimFx telah Dilarang pada halaman ini +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Preferensi item_help=Bantuan item_blacklist_button_tooltip=Larangan @@ -58,6 +59,7 @@ help_command_find=Masuk mode pencarian help_command_find_hl=Masuk mode pencarian menandai semua cocok help_command_find_next=Menuju temuan cocok setelah help_command_find_prev=Menuju temuan cocok sebelum +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Buka Toolbar Pengembang help=Bantuan diff --git a/extension/locale/nl/vimfx.properties b/extension/locale/nl/vimfx.properties index 2bb744d..a25a6d0 100644 --- a/extension/locale/nl/vimfx.properties +++ b/extension/locale/nl/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx is ingeschakeld. Klik om uit te schakelen (Shift-Alt-V) button_tooltip_disabled=VimFx is uitgeschakeld. Klik om in te schakelen (Shift-Alt-V) button_tooltip_blacklisted=VimFx is uitgeschakeld op deze pagina +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Instellingen item_help=Help item_blacklist_button_tooltip=Zwarte lijst @@ -59,6 +60,7 @@ help_command_find=Zoeken help_command_find_hl=Zoek met highlights help_command_find_next=Ga naar volgende overeenkomst help_command_find_prev=Ga naar vorige overeenkomst +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Open ontwikkelaarswerkbalk help=Help diff --git a/extension/locale/pl/vimfx.properties b/extension/locale/pl/vimfx.properties index 05a3ca9..758da21 100644 --- a/extension/locale/pl/vimfx.properties +++ b/extension/locale/pl/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx jest włączony. Kliknij, aby wyłączyć (Shift+Alt+V) button_tooltip_disabled=VimFx jest wyłączony. Kliknij, aby włączyć (Shift+Alt+V) button_tooltip_blacklisted=Ta strona jest na czarnej liście VimFx +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Preferencje item_help=Pomoc item_blacklist_button_tooltip=Czarna lista @@ -59,6 +60,7 @@ help_command_find=Znajdź help_command_find_hl=Znajdź i podkreśl wszystkie wystąpienia help_command_find_next=Znajdź następne help_command_find_prev=Znajdź poprzednie +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Otwórz pasek programisty help=Pomoc diff --git a/extension/locale/ru/vimfx.properties b/extension/locale/ru/vimfx.properties index da51e80..ecf22b5 100644 --- a/extension/locale/ru/vimfx.properties +++ b/extension/locale/ru/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx работает. Нажмите чтобы выключить (Shift+Alt+V) button_tooltip_disabled=VimFx не работает. Нажмите чтобы включить (Shift+Alt+V) button_tooltip_blacklisted=VimFx содержит текущую страницу в стоп-списке +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=Настройки item_help=Справка item_blacklist_button_tooltip=Добавить в стоп-список @@ -59,6 +60,7 @@ help_command_find=Режим поиска help_command_find_hl=Режим поиска с выделением всех совпадений help_command_find_next=Перейти к следующему результату поиска help_command_find_prev=Перейти к предыдущему результату поиска +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=Открыть Панель Разработки help=Справка diff --git a/extension/locale/zh-CN/vimfx.properties b/extension/locale/zh-CN/vimfx.properties index 5f61e5d..dbb90e1 100644 --- a/extension/locale/zh-CN/vimfx.properties +++ b/extension/locale/zh-CN/vimfx.properties @@ -1,6 +1,7 @@ button_tooltip_enabled=VimFx 已启用。点击禁用 (Shift+Alt+V) button_tooltip_disabled=VimFx 已禁用。点击启用 (Shift+Alt+V) button_tooltip_blacklisted=当前页面已被列入黑名单 +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc to exit item_preferences=首选项 item_help=帮助 item_blacklist_button_tooltip=添加到黑名单 @@ -59,6 +60,7 @@ help_command_find=进入查找模式 help_command_find_hl=进入查找模式并高亮所有匹配项 help_command_find_next=跳到下一个查找匹配项 help_command_find_prev=跳到上一个查找匹配项 +help_command_insert_mode=Enter insert mode: Ignore all commands until you hit esc to exit help_command_dev=打开开发者工具栏 help=帮助 diff --git a/extension/packages/button.coffee b/extension/packages/button.coffee index 9c4d57a..58e9f68 100644 --- a/extension/packages/button.coffee +++ b/extension/packages/button.coffee @@ -189,21 +189,29 @@ addToolbarButton = (window) -> $(doc, 'navigator-toolbox').palette.removeChild(button) updateToolbarButton = (button) -> - if getPref('disabled') - button.style.listStyleImage = iconUrl('grey') - button.setAttribute('tooltiptext', _('button_tooltip_disabled')) - else if button['VimFx_blacklisted'] - button.style.listStyleImage = iconUrl('red') - button.setAttribute('tooltiptext', _('button_tooltip_blacklisted')) - else - button.style.listStyleImage = iconUrl('normal') - button.setAttribute('tooltiptext', _('button_tooltip_enabled')) + switch + when getPref('disabled') + button.style.listStyleImage = iconUrl('grey') + button.setAttribute('tooltiptext', _('button_tooltip_disabled')) + when button['VimFx_blacklisted'] + button.style.listStyleImage = iconUrl('red') + button.setAttribute('tooltiptext', _('button_tooltip_blacklisted')) + when button['VimFx_insertMode'] + button.style.listStyleImage = iconUrl('grey') + button.setAttribute('tooltiptext', _('button_tooltip_insertMode')) + else + button.style.listStyleImage = iconUrl('normal') + button.setAttribute('tooltiptext', _('button_tooltip_enabled')) + +setWindow = (property, window, value) -> + return unless button = $(window.document, BUTTON_ID) + button[property] = value + updateToolbarButton(button) -setWindowBlacklisted = (window, blacklisted) -> - if button = $(window.document, BUTTON_ID) - button['VimFx_blacklisted'] = blacklisted - updateToolbarButton(button) +setWindowBlacklisted = setWindow.bind(undefined, 'VimFx_blacklisted') +setWindowInsertMode = setWindow.bind(undefined, 'VimFx_insertMode') exports.addToolbarButton = addToolbarButton exports.setWindowBlacklisted = setWindowBlacklisted +exports.setWindowInsertMode = setWindowInsertMode exports.setButtonInstallPosition = setButtonInstallPosition diff --git a/extension/packages/commands.coffee b/extension/packages/commands.coffee index f84b31d..d84af3f 100644 --- a/extension/packages/commands.coffee +++ b/extension/packages/commands.coffee @@ -268,13 +268,11 @@ command_find_prev = (vim, storage) -> if find.findStr.length > 0 storage.findRng = find.find(vim.window, find.findStr, storage.findRng, find.DIRECTION_BACKWARDS, true) +command_insert_mode = (vim) -> + vim.enterMode('insert') + command_Esc = (vim, storage, event) -> - # Only blur editable elements, in order not to interfere with the browser too much. TODO: Is that - # really needed? What if a website has made more elements focusable -- shouldn't those also be - # blurred? - { activeElement } = vim.window.document - if utils.isElementEditable(activeElement) - activeElement.blur() + utils.blurActiveElement(vim.window) # Also blur active XUL control if preferencess allow if getPref('blur_on_esc') @@ -363,6 +361,7 @@ commands = [ new Command('misc', 'find_hl', command_find_hl, ['a,/']) new Command('misc', 'find_next', command_find_next, ['n']) new Command('misc', 'find_prev', command_find_prev, ['N']) + new Command('misc', 'insert_mode', command_insert_mode, ['i']) new Command('misc', 'help', command_help, ['?']) new Command('misc', 'Esc', command_Esc, ['Esc']) new Command('misc', 'dev', command_dev, [':']) diff --git a/extension/packages/modes.coffee b/extension/packages/modes.coffee index be0283f..1a8685e 100644 --- a/extension/packages/modes.coffee +++ b/extension/packages/modes.coffee @@ -1,4 +1,16 @@ -{ mode_hints } = require 'mode-hints/mode-hints' +utils = require 'utils' +{ mode_hints } = require 'mode-hints/mode-hints' +{ setWindowInsertMode } = require 'button' exports.modes = hints: mode_hints + insert: + onEnter: (vim) -> + return unless rootWindow = utils.getRootWindow(vim.window) + setWindowInsertMode(rootWindow, true) + onInput: -> + return false + onEnterNormalMode: (vim) -> + return unless rootWindow = utils.getRootWindow(vim.window) + setWindowInsertMode(rootWindow, false) + utils.blurActiveElement(vim.window) diff --git a/extension/packages/utils.coffee b/extension/packages/utils.coffee index 633e16d..2e191f1 100644 --- a/extension/packages/utils.coffee +++ b/extension/packages/utils.coffee @@ -76,6 +76,14 @@ isElementEditable = (element) -> element.getAttribute('contenteditable')?.toLowerCase() == 'true' or \ element.ownerDocument?.designMode?.toLowerCase() == 'on' +blurActiveElement = (window) -> + # Only blur editable elements, in order not to interfere with the browser too much. TODO: Is that + # really needed? What if a website has made more elements focusable -- shouldn't those also be + # blurred? + { activeElement } = window.document + if isElementEditable(activeElement) + activeElement.blur() + getWindowId = (window) -> return window .QueryInterface(Components.interfaces.nsIInterfaceRequestor) @@ -279,6 +287,7 @@ exports.getWindowId = getWindowId exports.getRootWindow = getRootWindow exports.isTextInputElement = isTextInputElement exports.isElementEditable = isElementEditable +exports.blurActiveElement = blurActiveElement exports.getSessionStore = getSessionStore exports.loadCss = loadCss -- 2.39.3