From e0787aa7f86e75cec30908e4f57a644a82bf64b3 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Wed, 3 Feb 2016 18:11:33 +0100 Subject: [PATCH] Make the `H` and `L` commands more reliable It seems like using `window.BrowserBack()` and `window.BrowserForward()` are the most reliable ways of navigating the history, rather than having to wait for `SessionStore.getSessionHistory()` to finish and then going to a certain history index. This commit optimizes the case where the count is 1 to use the mentioned functions instead. Some extensions also override those, so calling them results in better interoperability. (Hopefully/Likely) fixes #687. To keep the code changes simple, the support for Firefox < 43 was dropped. That's fine, since Firefox 44 has already been released. --- extension/lib/commands.coffee | 47 +++++++++++++++++++++-------------- package.json | 2 +- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index f55ac70..0f65597 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -68,24 +68,35 @@ commands.go_home = ({vim}) -> vim.window.BrowserHome() helper_go_history = (direction, {vim, count = 1}) -> - {SessionStore, gBrowser} = vim.window - - # TODO: When Firefox 43 is released, only use the `.getSessionHistory` - # version and bump the minimum Firefox version. - if SessionStore.getSessionHistory - SessionStore.getSessionHistory(gBrowser.selectedTab, (sessionHistory) -> - {index} = sessionHistory - newIndex = index + count * (if direction == 'back' then -1 else 1) - newIndex = Math.max(newIndex, 0) - newIndex = Math.min(newIndex, sessionHistory.entries.length - 1) - if newIndex == index - vim.notify(translate("notification.history_#{direction}.limit")) - else - gBrowser.gotoIndex(newIndex) - ) - else - # Until then, fall back to a no-count version. - if direction == 'back' then gBrowser.goBack() else gBrowser.goForward() + {window} = vim + {SessionStore, gBrowser} = window + + if (direction == 'back' and not gBrowser.canGoBack) or + (direction == 'forward' and not gBrowser.canGoForward) + vim.notify(translate("notification.history_#{direction}.limit")) + return + + # `SessionStore.getSessionHistory()` (used below to support counts) starts + # lots of asynchronous tasks internally, which is a bit unreliable, it has + # turned out. The primary use of the `history_back` and `history_forward` + # commands is to go _one_ step back or forward, though, so those cases are + # optimized to use more reliable ways of going back and forward. Also, some + # extensions override the following functions, so calling them also gives + # better interoperability. + if count == 1 + if direction == 'back' + window.BrowserBack() + else + window.BrowserForward() + return + + SessionStore.getSessionHistory(gBrowser.selectedTab, (sessionHistory) -> + {index} = sessionHistory + newIndex = index + count * (if direction == 'back' then -1 else 1) + newIndex = Math.max(newIndex, 0) + newIndex = Math.min(newIndex, sessionHistory.entries.length - 1) + gBrowser.gotoIndex(newIndex) + ) commands.history_back = helper_go_history.bind(null, 'back') diff --git a/package.json b/package.json index 177914f..53ab966 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "VimFx", "version": "0.11.0", "firefoxVersions": { - "min": "40.0", + "min": "43.0", "max": "45.*" }, "license": "GPL-3.0+", -- 2.39.3