From fe46fb15284de6987aeb82aa126f0858ac933977 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Wed, 21 Sep 2016 08:51:03 +0200 Subject: [PATCH] Improve scrolling when holding h/l/j/k down When you hold an arrow key down, the scrolling is sped up. With this commit, the `h`, `l`, `j` and `k` do too, to be as close the the arrow keys as possible. Note that this includes a minor breaking API change: The object passed to modes' `onInput`, and thus the object passed to commands, no longer has the `uiEvent` property. Instead, there's an `event` property, which _always_ is an `Event`. `vim.isUIEvent(event)` can be used to check if it is a UI event or not. --- documentation/api.md | 3 +-- documentation/options.md | 7 +++++++ extension/lib/commands.coffee | 28 ++++++++++++++++------------ extension/lib/defaults.coffee | 2 ++ extension/lib/modes.coffee | 6 +++--- extension/lib/vim.coffee | 3 +-- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/documentation/api.md b/documentation/api.md index 23352cc..283a33f 100644 --- a/documentation/api.md +++ b/documentation/api.md @@ -600,8 +600,7 @@ with. The object passed to this method (see above) also has the following properties: -- uiEvent: `Event` or `false`. The keydown event object if the event occurred in - the browser UI, `false` otherwise (if the event occurred in web page content). +- event: `Event`. The keydown event object. - count: `Number`. The count for the command. `undefined` if no count. (This is simply a copy of `match.count`. `match` is defined below.) diff --git a/documentation/options.md b/documentation/options.md index fd36c5b..e8a8023 100644 --- a/documentation/options.md +++ b/documentation/options.md @@ -471,6 +471,13 @@ much they scroll by adjusting the following options: (VimFx used to have a `scroll_step` option, but is has been replaced by the above.) +#### `scroll.horizontal_boost` and `scroll.vertical_boost` + +When holding down `h`, `l`, `j` or `k` (rather than just tapping those keys), +their scrolling speed is sped up, just like when you hold down an arrow key to +scroll. These options control _how much_ the mentioned commands are sped up. The +usual scroll distances are multiplied by these numbers. + #### `scroll.full_page_adjustment` and `scroll.half_page_adjustment` An important use case for scrolling a full page down is to read an entire page diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 7827920..8265089 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -152,7 +152,7 @@ springConstant = { value: null } -helper_scroll = (vim, uiEvent, args...) -> +helper_scroll = (vim, event, args...) -> [ method, type, directions, amounts properties = null, adjustment = 0, name = 'scroll' @@ -183,7 +183,7 @@ helper_scroll = (vim, uiEvent, args...) -> ), vim.options['scroll.reset_timeout']) helpScroll = help.getHelp(vim.window)?.querySelector('.wrapper') - if uiEvent or helpScroll + if vim.isUIEvent(event) or helpScroll activeElement = helpScroll or utils.getActiveElement(vim.window) if vim._state.scrollableElements.has(activeElement) or helpScroll viewportUtils.scroll(activeElement, options) @@ -193,35 +193,39 @@ helper_scroll = (vim, uiEvent, args...) -> vim._run(name, options, reset) -helper_scrollByLinesX = (amount, {vim, uiEvent, count = 1}) -> +helper_scrollByLinesX = (amount, {vim, event, count = 1}) -> distance = prefs.root.get('toolkit.scrollbox.horizontalScrollDistance') + boost = if event.repeat then vim.options['scroll.horizontal_boost'] else 1 helper_scroll( - vim, uiEvent, 'scrollBy', 'lines', ['left'], [amount * distance * count * 5] + vim, event, 'scrollBy', 'lines', ['left'], + [amount * distance * boost * count * 5] ) -helper_scrollByLinesY = (amount, {vim, uiEvent, count = 1}) -> +helper_scrollByLinesY = (amount, {vim, event, count = 1}) -> distance = prefs.root.get('toolkit.scrollbox.verticalScrollDistance') + boost = if event.repeat then vim.options['scroll.vertical_boost'] else 1 helper_scroll( - vim, uiEvent, 'scrollBy', 'lines', ['top'], [amount * distance * count * 20] + vim, event, 'scrollBy', 'lines', ['top'], + [amount * distance * boost * count * 20] ) -helper_scrollByPagesY = (amount, type, {vim, uiEvent, count = 1}) -> +helper_scrollByPagesY = (amount, type, {vim, event, count = 1}) -> adjustment = vim.options["scroll.#{type}_page_adjustment"] helper_scroll( - vim, uiEvent, 'scrollBy', 'pages', ['top'], [amount * count], + vim, event, 'scrollBy', 'pages', ['top'], [amount * count], ['clientHeight'], adjustment ) -helper_scrollToX = (amount, {vim, uiEvent}) -> +helper_scrollToX = (amount, {vim, event}) -> helper_mark_last_scroll_position(vim) helper_scroll( - vim, uiEvent, 'scrollTo', 'other', ['left'], [amount], ['scrollLeftMax'] + vim, event, 'scrollTo', 'other', ['left'], [amount], ['scrollLeftMax'] ) -helper_scrollToY = (amount, {vim, uiEvent}) -> +helper_scrollToY = (amount, {vim, event}) -> helper_mark_last_scroll_position(vim) helper_scroll( - vim, uiEvent, 'scrollTo', 'other', ['top'], [amount], ['scrollTopMax'] + vim, event, 'scrollTo', 'other', ['top'], [amount], ['scrollTopMax'] ) commands.scroll_left = helper_scrollByLinesX.bind(null, -1) diff --git a/extension/lib/defaults.coffee b/extension/lib/defaults.coffee index 465528e..f84753d 100644 --- a/extension/lib/defaults.coffee +++ b/extension/lib/defaults.coffee @@ -182,6 +182,8 @@ advanced_options = 'smoothScroll.pages.spring-constant': '2500' 'smoothScroll.other.spring-constant': '2500' 'scroll.reset_timeout': 1000 + 'scroll.horizontal_boost': 6 + 'scroll.vertical_boost': 3 'scroll.full_page_adjustment': 40 'scroll.half_page_adjustment': 20 'scroll.last_position_mark': "'" diff --git a/extension/lib/modes.coffee b/extension/lib/modes.coffee index 0521ed4..8dfb67a 100644 --- a/extension/lib/modes.coffee +++ b/extension/lib/modes.coffee @@ -62,7 +62,7 @@ mode('normal', { vim._run('clear_inputs') onInput: (args, match) -> - {vim, storage, uiEvent} = args + {vim, storage, event} = args {keyStr} = match vim.hideNotification() if match.type in ['none', 'full'] @@ -93,13 +93,13 @@ mode('normal', { # Passing Escape through allows for stopping the loading of the page and # closing many custom dialogs (and perhaps other things; Escape is a very # commonly used key). - if uiEvent + if vim.isUIEvent(event) # In browser UI the biggest reasons are allowing to reset the location bar # when blurring it, and closing dialogs such as the “bookmark this page” # dialog (). However, an exception is made for the devtools (). # There, trying to unfocus the devtools using Escape would annoyingly # open the split console. - return utils.isDevtoolsElement(uiEvent.originalTarget) + return utils.isDevtoolsElement(event.originalTarget) else # In web pages content, an exception is made if an element that VimFx # cares about is focused. That allows for blurring an input in a custom diff --git a/extension/lib/vim.coffee b/extension/lib/vim.coffee index c0a25d6..ab3b203 100644 --- a/extension/lib/vim.coffee +++ b/extension/lib/vim.coffee @@ -148,8 +148,7 @@ class Vim return match _onInput: (match, event) -> - uiEvent = if @isUIEvent(event) then event else false - suppress = @_call('onInput', {uiEvent, count: match.count}, match) + suppress = @_call('onInput', {event, count: match.count}, match) return suppress _onLocationChange: (url) -> -- 2.39.3