From 1f8481e7726fd99eb398ac9d49adadc3a8b7357c Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 9 Sep 2016 21:11:56 +0200 Subject: [PATCH] Add `ep` for opening links in new private windows Fixes #771. --- documentation/api.md | 21 ++++++++++----------- documentation/commands.md | 8 +++++--- extension/lib/commands.coffee | 10 ++++++++-- extension/lib/defaults.coffee | 1 + extension/locale/de/vimfx.properties | 1 + extension/locale/en-US/vimfx.properties | 1 + extension/locale/es/vimfx.properties | 1 + extension/locale/fr/vimfx.properties | 1 + extension/locale/id/vimfx.properties | 1 + extension/locale/it/vimfx.properties | 1 + extension/locale/ja/vimfx.properties | 1 + extension/locale/nl/vimfx.properties | 1 + extension/locale/pt-BR/vimfx.properties | 1 + extension/locale/ru/vimfx.properties | 1 + extension/locale/sv-SE/vimfx.properties | 1 + extension/locale/zh-CN/vimfx.properties | 1 + extension/locale/zh-TW/vimfx.properties | 1 + 17 files changed, 37 insertions(+), 16 deletions(-) diff --git a/documentation/api.md b/documentation/api.md index 810acf1..2bd83e8 100644 --- a/documentation/api.md +++ b/documentation/api.md @@ -528,25 +528,24 @@ and `false` if you wish to exit Hints mode. If your command ignores counts, simply always return `false`. Otherwise you most likely want to return `timesLeft > 1`. -Here’s an example which adds a command for opening a link in a new private -window using hint markers. It also highlights those links with a red background. +Here’s an example which adds a silly command for marking links with +color—`http://` links with red and all other links with green. ```js // config.js let {commands} = vimfx.modes.normal vimfx.addCommand({ - name: 'follow_in_private_window', + name: 'mark_link', category: 'browsing', - order: commands.follow_in_window.order + 1, - description: 'Follow link in a new private window', + description: 'Mark link with red or green', }, (args) => { let {vim} = args - commands.follow_in_window.run(Object.assign({}, args, { + commands.follow_in_tab.run(Object.assign({}, args, { callbackOverride({type, href, id, timesLeft}) { if (href) { - vim.window.openLinkIn(href, 'window', {private: true}) - vimfx.send(vim, 'highlight_marker_element', {id}) + let color = href.startsWith('http://') ? 'red' : 'green' + vimfx.send(vim, 'highlight_marker_element', {id, color}) } return false }, @@ -556,10 +555,10 @@ vimfx.addCommand({ ```js // frame.js -vimfx.listen('highlight_marker_element', ({id}) => { +vimfx.listen('highlight_marker_element', ({id, color}) => { let element = vimfx.getMarkerElement(id) if (element) { - element.style.backgroundColor = 'red' + element.style.backgroundColor = color } }) ``` @@ -831,7 +830,7 @@ The arguments passed to the `hintMatcher` function are: - id: `String`. A string identifying which command is used: - `'normal'`: `f` or `af`. - - `'tab'`: `F`, `et` or `ew`. + - `'tab'`: `F`, `et`, `ew` or `ep`. - `'copy'`: `yf`. - `'focus'`: `ef`. - `'select'`: `v`, `av` or `yv`. diff --git a/documentation/commands.md b/documentation/commands.md index f4e355b..fc84ad7 100644 --- a/documentation/commands.md +++ b/documentation/commands.md @@ -206,7 +206,8 @@ command (`/`), except that it searches links only. Which elements get hints depends on the command as well: - `f` and `af`: Anything clickable—links, buttons, form controls. -- `F`, `et` and `ew`: Anything that can be opened in a new tab or window—links. +- `F`, `et`, `ew` and `ep`: Anything that can be opened in a new tab or + window—links. - `yf`: Anything that has something useful to copy—links (their URL) and text inputs (their text). - `ef`: Anything focusable—links, buttons, form controls, scrollable elements, @@ -299,8 +300,9 @@ key/letter, because it is close to `f` both alphabetically, and physically in many keyboard layouts (and is pretty easy to type). The second key after `e` was chosen based on mnemonics: There’s `et` as in -tab, `ew` as in window, `ef` as in -focus and `eb` as in browser. +tab, `ew` as in window, `ep` as in +private window, `ef` as in focus and `eb` as +in browser. [`v` commands]: #the-v-commands--caret-mode [hint-matcher]: api.md#vimfxsethintmatcherhintmatcher diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index b753fba..90768aa 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -551,17 +551,23 @@ commands.follow_in_tab = commands.follow_in_focused_tab = helper_follow_clickable.bind(null, {inTab: true, inBackground: false}) -commands.follow_in_window = (args) -> +helper_follow_in_window = (options, args) -> {vim} = args callback = (marker) -> vim._focusMarkerElement(marker.wrapper.elementIndex) {href} = marker.wrapper - vim.window.openLinkIn(href, 'window', {}) if href + vim.window.openLinkIn(href, 'window', options) if href return false helper_follow({name: 'follow_in_tab', callback}, args) +commands.follow_in_window = + helper_follow_in_window.bind(null, {}) + +commands.follow_in_private_window = + helper_follow_in_window.bind(null, {private: true}) + commands.follow_multiple = (args) -> args.count = Infinity commands.follow(args) diff --git a/extension/lib/defaults.coffee b/extension/lib/defaults.coffee index 165ba51..5674ece 100644 --- a/extension/lib/defaults.coffee +++ b/extension/lib/defaults.coffee @@ -85,6 +85,7 @@ shortcuts = 'F': 'follow_in_tab' 'et': 'follow_in_focused_tab' 'ew': 'follow_in_window' + 'ep': 'follow_in_private_window' 'af': 'follow_multiple' 'yf': 'follow_copy' 'ef': 'follow_focus' diff --git a/extension/locale/de/vimfx.properties b/extension/locale/de/vimfx.properties index 471629d..9bc31d5 100644 --- a/extension/locale/de/vimfx.properties +++ b/extension/locale/de/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Einem Link auf der aktuellen Seite folgen mode.normal.follow_in_tab=Einen Link in neuem Tab öffnen mode.normal.follow_in_focused_tab=Einen Link in neuem Tab im Vordergrund öffnen mode.normal.follow_in_window=Einen Link in neuem Fenster öffnen +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Mehreren Links in neuen Tabs folgen, Texteingabe fokussieren oder mehrere Schaltflächen betätigen mode.normal.follow_copy=Links oder Text-Eingabewerte in Zwischenablage kopieren mode.normal.follow_focus=Element fokussieren oder auswählen diff --git a/extension/locale/en-US/vimfx.properties b/extension/locale/en-US/vimfx.properties index 2df63d6..e9e1384 100644 --- a/extension/locale/en-US/vimfx.properties +++ b/extension/locale/en-US/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Follow link, focus text input or click button mode.normal.follow_in_tab=Follow link in a new background tab mode.normal.follow_in_focused_tab=Follow link in a new foreground tab mode.normal.follow_in_window=Follow link in a new window +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Follow multiple links in new background tabs, focus text input or click multiple buttons mode.normal.follow_copy=Copy link or text input value mode.normal.follow_focus=Focus/select element diff --git a/extension/locale/es/vimfx.properties b/extension/locale/es/vimfx.properties index 9ec6f73..b5d995d 100644 --- a/extension/locale/es/vimfx.properties +++ b/extension/locale/es/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Seguir enlace, poner foco en la entrada de texto o pulsar bot mode.normal.follow_in_tab=Seguir enlace en una nueva pestaña en 2º plano mode.normal.follow_in_focused_tab=Seguir enlace en una nueva pestaña en 1º plano mode.normal.follow_in_window=Seguir enlace en una nueva ventana +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Seguir múltiples enlaces en nuevas pestañas en 2º plano, poner foco en entrada de texto o pulsar varios botones mode.normal.follow_copy=Copiar enlace o valor de la entrada de texto mode.normal.follow_focus=Poner foco en / Seleccionar elemento diff --git a/extension/locale/fr/vimfx.properties b/extension/locale/fr/vimfx.properties index f6a3714..9648fa2 100644 --- a/extension/locale/fr/vimfx.properties +++ b/extension/locale/fr/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Ouvrir un lien dans l'onglet courant mode.normal.follow_in_tab=Ouvrir un lien dans un nouvel onglet en arrière-plan mode.normal.follow_in_focused_tab=Ouvrir le lien dans un nouvel onglet au premier plan mode.normal.follow_in_window=Ouvrir le lien dans un nouvel onglet +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Ouvrir plusieurs liens dans des onglets en arrière-plan mode.normal.follow_copy=Copier l'adresse du lien ou le texte dans le presse-papier mode.normal.follow_focus=Focaliser l'élément diff --git a/extension/locale/id/vimfx.properties b/extension/locale/id/vimfx.properties index bfca365..b01b0b3 100644 --- a/extension/locale/id/vimfx.properties +++ b/extension/locale/id/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Ikuti link, fokus masukan teks atau klik tombol mode.normal.follow_in_tab=Ikuti link pada tab latar belakang baru mode.normal.follow_in_focused_tab=Ikuti link pada tab latar depan baru mode.normal.follow_in_window=Ikuti link pada jendela baru +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Ikuti banyak link pada tab latar belakang baru, fokus masukan teks atau klik banyak tombol mode.normal.follow_copy=Salin link atau isi masukan teks mode.normal.follow_focus=Fokus/pilih element diff --git a/extension/locale/it/vimfx.properties b/extension/locale/it/vimfx.properties index 58654a3..50b46e9 100644 --- a/extension/locale/it/vimfx.properties +++ b/extension/locale/it/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Apri un link nella pagina corrente mode.normal.follow_in_tab=Apri il collegamento in una nuova scheda in secondo piano mode.normal.follow_in_focused_tab=Apri il collegamento in una nuova scheda in primo piano mode.normal.follow_in_window=Apri il collegamento in una nuova finestra +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Apri diversi link in nuove schede non in primo piano, seleziona una casella di input di testo o clicca diversi bottoni. mode.normal.follow_copy=Copia il link o il testo nella casella negli appunti mode.normal.follow_focus=Attiva/seleziona elemento diff --git a/extension/locale/ja/vimfx.properties b/extension/locale/ja/vimfx.properties index 2c12a4b..79e02ce 100644 --- a/extension/locale/ja/vimfx.properties +++ b/extension/locale/ja/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=リンク先へ移動して、テキスト入力やボタン mode.normal.follow_in_tab=新規バックグラウンドタブでリンク先を開く mode.normal.follow_in_focused_tab=新規フォアグラウンドタブでリンク先を開く mode.normal.follow_in_window=新規ウィンドウでリンク先を開く +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=複数のリンクを新規バックグラウンドタブで開き、テキスト入力やボタンにフォーカス mode.normal.follow_copy=URLまたは入力値をクリップボードにコピー mode.normal.follow_focus=要素にフォーカス/選択 diff --git a/extension/locale/nl/vimfx.properties b/extension/locale/nl/vimfx.properties index 0fe0e8e..6b9ff43 100644 --- a/extension/locale/nl/vimfx.properties +++ b/extension/locale/nl/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Volg een link op de huidige pagina mode.normal.follow_in_tab=Volg een link naar een achtergrondtabblad mode.normal.follow_in_focused_tab=Volg een link naar een voorgrondtabblad mode.normal.follow_in_window=Volg link in een nieuw venster +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Volg meerdere links naar achtergrondtabbladen, focus het volgende invoerveld or klik op meerdere knoppen mode.normal.follow_copy=Kopieer link-URL of tekstinvoer naar klembord mode.normal.follow_focus=Focus/selecteer element diff --git a/extension/locale/pt-BR/vimfx.properties b/extension/locale/pt-BR/vimfx.properties index 34911b7..cb38160 100644 --- a/extension/locale/pt-BR/vimfx.properties +++ b/extension/locale/pt-BR/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Seguir link, foco no campo texto ou clique em botão mode.normal.follow_in_tab=Seguir link numa aba em segundo plano mode.normal.follow_in_focused_tab=Seguir link numa aba em primeiro plano mode.normal.follow_in_window=Seguir link em uma nova janela +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Seguir múltiplos links em abas em segundo plano, foco no campo texto ou clique em múltiplos botões mode.normal.follow_copy=Copiar link ou valor do campo texto mode.normal.follow_focus=Focar/selecionar elemento diff --git a/extension/locale/ru/vimfx.properties b/extension/locale/ru/vimfx.properties index 4148964..4f2ecae 100644 --- a/extension/locale/ru/vimfx.properties +++ b/extension/locale/ru/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Перейти по ссылке mode.normal.follow_in_tab=Перейти по ссылке в новой фоновой вкладке mode.normal.follow_in_focused_tab=Перейти по ссылке в новой вкладке на первом плане mode.normal.follow_in_window=Перейти по ссылке в новом окне +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=Перейти по нескольким ссылкам в новых вкладках, сфокусироваться на поле ввода или щелкнуть по нескольким кнопкам mode.normal.follow_copy=Скопировать в буфер обмена адрес ссылки или текст в поле ввода mode.normal.follow_focus=Фокус на/выбрать элемент diff --git a/extension/locale/sv-SE/vimfx.properties b/extension/locale/sv-SE/vimfx.properties index 7fca69e..27ea819 100644 --- a/extension/locale/sv-SE/vimfx.properties +++ b/extension/locale/sv-SE/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=Följ länk, fokusera textruta eller klicka på knapp mode.normal.follow_in_tab=Följ länk i ny bakgrundsflik mode.normal.follow_in_focused_tab=Följ länk i ny förgrundsflik mode.normal.follow_in_window=Följ länk i nytt fönster +mode.normal.follow_in_private_window=Följ länk i nytt privat fönster mode.normal.follow_multiple=Följ flera länkar i nya bakgrundsflikar, fokusera textruta eller klicka på flera knappar mode.normal.follow_copy=Kopiera länkadress eller inmatad text mode.normal.follow_focus=Fokusera/markera element diff --git a/extension/locale/zh-CN/vimfx.properties b/extension/locale/zh-CN/vimfx.properties index 4f8cdd0..7157747 100644 --- a/extension/locale/zh-CN/vimfx.properties +++ b/extension/locale/zh-CN/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=打开链接,聚焦输入框或点击按钮 mode.normal.follow_in_tab=在新的后台标签页中打开此链接 mode.normal.follow_in_focused_tab=在新的前台标签页中打开此链接 mode.normal.follow_in_window=在新的窗口中打开此链接 +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=在新的后台标签页中打开多个链接,聚焦输入框或点击多个按钮 mode.normal.follow_copy=复制链接地址或输入框文本 mode.normal.follow_focus=聚焦/选中元素 diff --git a/extension/locale/zh-TW/vimfx.properties b/extension/locale/zh-TW/vimfx.properties index 9f0dcd2..0d1db6b 100644 --- a/extension/locale/zh-TW/vimfx.properties +++ b/extension/locale/zh-TW/vimfx.properties @@ -68,6 +68,7 @@ mode.normal.follow=開啟連結,焦點放在文字輸入框或按鈕 mode.normal.follow_in_tab=在新背景分頁中開啟連結 mode.normal.follow_in_focused_tab=在新前景分頁中開啟連結 mode.normal.follow_in_window=在新視窗中開啟連結 +mode.normal.follow_in_private_window=Follow link in a new private window mode.normal.follow_multiple=用新背景分頁開啟多個連結,焦點放在文字輸入框或按鈕 mode.normal.follow_copy=複製連結或輸入框中的文字 mode.normal.follow_focus=移動焦點/選取元素 -- 2.39.3