From d0d04fc44572635d5b9302a90cf219f52b618841 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 3 Dec 2016 22:56:01 +0100 Subject: [PATCH] Improve holding keys for scrolling by page Fixes #843. --- documentation/options.md | 9 +++++++++ extension/lib/commands.coffee | 25 +++++++++++++++++-------- extension/lib/defaults.coffee | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/documentation/options.md b/documentation/options.md index abd65d6..0c7a89b 100644 --- a/documentation/options.md +++ b/documentation/options.md @@ -486,6 +486,15 @@ Firefox’s `layout.css.scroll-behavior.spring-constant` option. It is reset aga after one second (by default). If that doesn’t work out for you, you can customize that timeout using the `scroll.reset_timeout` option. +Another quirk of Firefox’s smooth scrolling is that it doesn’t like if you ask +for smooth scrolling too often: The scrolling can get stuttery, progressively +slower and even grind to a halt. On a long page with lots of elements, simply +holding `d`, `u`, `` or `` can be too much. By default, keyboard +software typically repeats keypresses every 30ms when holding keys. Because of +this, VimFx only asks for smooth scrolling if more than 65ms (two repeats) has +passed since the last request. You can customize that timeout via the +`scroll.repeat_timeout` option. + The Firefox option `general.smoothScroll` lets you turn off smooth scrolling entirely, including all of VimFx’s scrolling commands. diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 3a6e85c..1fcf56f 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -147,9 +147,10 @@ commands.stop_all = ({vim}) -> -springConstant = { +scrollData = { nonce: null - value: null + springConstant: null + lastRepeat: 0 } helper_scroll = (vim, event, args...) -> @@ -157,6 +158,14 @@ helper_scroll = (vim, event, args...) -> method, type, directions, amounts properties = null, adjustment = 0, name = 'scroll', extra = {} ] = args + + elapsed = event.timeStamp - scrollData.lastRepeat + + if event.repeat and elapsed < vim.options['scroll.repeat_timeout'] + return + + scrollData.lastRepeat = event.timeStamp + options = { method, type, directions, amounts, properties, adjustment, extra smooth: ( @@ -168,18 +177,18 @@ helper_scroll = (vim, event, args...) -> # Temporarily set Firefox’s “spring constant” pref to get the desired smooth # scrolling speed. Reset it `reset_timeout` milliseconds after the last # scrolling command was invoked. - springConstant.nonce = nonce = {} - springConstant.value ?= prefs.root.get(SPRING_CONSTANT_PREF) + scrollData.nonce = nonce = {} + scrollData.springConstant ?= prefs.root.get(SPRING_CONSTANT_PREF) prefs.root.set( SPRING_CONSTANT_PREF, vim.options["smoothScroll.#{type}.spring-constant"] ) reset = -> vim.window.setTimeout((-> - return unless springConstant.nonce == nonce - prefs.root.set(SPRING_CONSTANT_PREF, springConstant.value) - springConstant.nonce = null - springConstant.value = null + return unless scrollData.nonce == nonce + prefs.root.set(SPRING_CONSTANT_PREF, scrollData.springConstant) + scrollData.nonce = null + scrollData.springConstant = null ), vim.options['scroll.reset_timeout']) helpScroll = help.getHelp(vim.window)?.querySelector('.wrapper') diff --git a/extension/lib/defaults.coffee b/extension/lib/defaults.coffee index 6dcf7dd..eb7581f 100644 --- a/extension/lib/defaults.coffee +++ b/extension/lib/defaults.coffee @@ -186,6 +186,7 @@ advanced_options = 'smoothScroll.pages.spring-constant': '2500' 'smoothScroll.other.spring-constant': '2500' 'scroll.reset_timeout': 1000 + 'scroll.repeat_timeout': 65 'scroll.horizontal_boost': 6 'scroll.vertical_boost': 3 'scroll.full_page_adjustment': 40 -- 2.39.3