From 1606cb8bab69a7f79a2c11bfb6ec88bdfbf7a4c0 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 10 Jan 2017 07:53:00 +0100 Subject: [PATCH] Scroll closest scrollable parent If you click a tweet on Twitter, a modal with the tweet as well as responses to it pop up. That modal can be scrollable if there are enough responses. The container for the main tweet is focused. It feels very natural that the _modal_ should scroll when using VimFx commands, not the page behind it. That used not to be the case, but now is. This was implemented by not just checking if the active element _itself_ is scrollable, but also whether one of its _parents_ are scrollable, and using the closest scrollable parent (if any). --- extension/lib/commands-frame.coffee | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extension/lib/commands-frame.coffee b/extension/lib/commands-frame.coffee index 833b53b..27d7887 100644 --- a/extension/lib/commands-frame.coffee +++ b/extension/lib/commands-frame.coffee @@ -82,15 +82,23 @@ commands.go_to_root = ({vim}) -> commands.scroll = (args) -> {vim} = args return unless activeElement = utils.getActiveElement(vim.content) + + # If the active element, or one of its parents, is scrollable, use that + # element. + scrollElement = activeElement + until vim.state.scrollableElements.has(scrollElement) or + not scrollElement.parentNode + scrollElement = scrollElement.parentNode + element = # If no element is focused on the page, the active element is the topmost # ``, and blurring it is a no-op. If it is scrollable, it means that # you can’t blur it in order to scroll ``. Therefore it may only be # scrolled if it has been explicitly focused. - if vim.state.scrollableElements.has(activeElement) and - (activeElement != vim.content.document.body or + if vim.state.scrollableElements.has(scrollElement) and + (scrollElement != vim.content.document.body or vim.state.explicitBodyFocus) - activeElement + scrollElement else vim.state.scrollableElements.filterSuitableDefault() viewportUtils.scroll(element, args) -- 2.39.3