From adf01041e772037f406a2fe887a59edc808e89d3 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Wed, 22 Jun 2016 08:02:36 +0200 Subject: [PATCH] Teach the `zF` command to find and activate dropmarkers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For example, the bookmarks button has a "star" button on the left, which acts like a normal button, and another button on the right, which actually is a `` and opens a ``. Previously, VimFx didn't find the `` (because it hasn't got `.tabIndex > `-1). Now it does. Note that simulating a click on a `` triggers its parent button's action. Instead, the `` must be found and triggered manually. Another example of such a button is Greasemonkey’s button. Actually, this "button with dropmarker" concept seems pretty common among add-ons. This commit also removes the unnecessary double hint for the bookmarks button, but filtering out ``s which are direct children of another ``. Fixes #766. --- extension/lib/commands.coffee | 17 +++++++++++++++++ extension/lib/utils.coffee | 2 ++ 2 files changed, 19 insertions(+) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index a3cb164..0bbc4b5 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -573,10 +573,19 @@ commands.click_browser_element = ({vim}) -> {window} = vim markerElements = [] + getButtonMenu = (element) -> + if element.localName == 'dropmarker' and + element.parentNode?.localName == 'toolbarbutton' + return element.parentNode.querySelector('menupopup') + else + return null + filter = ({complementary}, element, getElementShape) -> type = switch when vim._state.scrollableElements.has(element) 'scrollable' + when getButtonMenu(element) + 'dropmarker' when utils.isFocusable(element) or (element.onclick and element.localName != 'statuspanel') 'clickable' @@ -600,6 +609,14 @@ commands.click_browser_element = ({vim}) -> switch marker.wrapper.type when 'scrollable' utils.focusElement(element, {flag: 'FLAG_BYKEY'}) + when 'dropmarker' + getButtonMenu(element).openPopup( + element.parentNode, # Anchor node. + 'after_end', # Position. + 0, 0, # Offset. + false, # Isn’t a context menu. + true, # Allow the 'position' attribute to override the above position. + ) when 'clickable', 'complementary' # VimFx’s own button won’t trigger unless the click is simulated in the # next tick. This might be true for other buttons as well. diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index ee8f939..63b5321 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -103,6 +103,8 @@ isFocusable = (element) -> return element.tabIndex > -1 and not (element.localName?.endsWith?('box') and element.localName != 'checkbox') and + not (element.localName == 'toolbarbutton' and + element.parentNode?.localName == 'toolbarbutton') and element.localName not in ['tabs', 'menuitem', 'menuseparator'] isIframeEditor = (element) -> -- 2.39.3