aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-02-08 10:45:42 +0000
committerStephen Blott2015-02-08 10:45:42 +0000
commitd27136549f24f65ec0429dc5d845de1f609ff559 (patch)
tree9496fe8fb5ffece0b994cb00aae7de75c0c408bf /content_scripts
parentb071067a0036a4bd3ce6d2bba8e00fadfd372e21 (diff)
downloadvimium-d27136549f24f65ec0429dc5d845de1f609ff559.tar.bz2
Handle incognito mode for find-mode history.
The approach is to maintain the "current" history in every tab, adding queries from other normal tabs in all tabs, but only saving queries from non-incognito mode tabs. So, queries from non-incognito mode tabs propagate everywhere, whereas those from incognito tabs never leave the tab.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/vimium_frontend.coffee28
1 files changed, 20 insertions, 8 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index cf7aadca..2824a09d 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -47,6 +47,7 @@ settings =
"userDefinedLinkHintCss", "helpDialog_showAdvancedCommands", "smoothScroll" ]
isLoaded: false
eventListeners: {}
+ postUpdateHooks: {}
init: ->
@port = chrome.runtime.connect({ name: "settings" })
@@ -77,7 +78,11 @@ settings =
receiveMessage: (args) ->
# not using 'this' due to issues with binding on callback
+ settingChanged = settings.values[args.key] != args.value
settings.values[args.key] = args.value
+ # Settings values are refreshed every time the tab/focus changes. We only call any post-update hook if
+ # the setting's value has in fact changed.
+ settings.postUpdateHooks[args.key]? args.value if settingChanged
# since load() can be called more than once, loadedValues can be greater than valuesToLoad, but we test
# for equality so initializeOnReady only runs once
if (++settings.loadedValues == settings.valuesToLoad.length)
@@ -188,7 +193,6 @@ setState = (request) ->
isEnabledForUrl = request.enabled
passKeys = request.passKeys
isIncognitoMode = request.incognito
- console.log "isIncognitoMode", isIncognitoMode
initializeWhenEnabled() if isEnabledForUrl
handlerStack.bubbleEvent "registerStateChange",
enabled: isEnabledForUrl
@@ -537,19 +541,27 @@ window.refreshCompletionKeys = (response) ->
isValidFirstKey = (keyChar) ->
validFirstKeys[keyChar] || /^[1-9]/.test(keyChar)
-# This implements a find-mode query history (using the "findModeRawQueryList" setting) as a list of raw
-# queries, most recent first.
+# This implements find-mode query history (using the "findModeRawQueryList" setting) as a list of raw queries,
+# most recent first.
FindModeHistory =
+ max: 50
rawQueryList: null
+ postUpdateHook: do ->
+ settings.postUpdateHooks.findModeRawQueryList = ( rawQueryList ) -> FindModeHistory.postUpdateHook rawQueryList
+ (rawQueryList) ->
+ @rawQueryList ||= rawQueryList
+ @updateRawQueryList rawQueryList[0] if rawQueryList[0]?
+
+ updateRawQueryList: (query) ->
+ @rawQueryList = ([ query ].concat @rawQueryList.filter (q) => q != query)[0..@max]
+
getQuery: (index = 0) ->
- @rawQueryList = settings.get "findModeRawQueryList" unless @rawQueryList
- if index < @rawQueryList.length then @rawQueryList[index] else ""
+ if @rawQueryList and index < @rawQueryList.length then @rawQueryList[index] else ""
saveQuery: (query) ->
- @rawQueryList = settings.get "findModeRawQueryList" unless @rawQueryList
- if 0 < query.length
- @rawQueryList = ([ query ].concat @rawQueryList.filter (q) -> q != query)[0..50]
+ @updateRawQueryList query if 0 < query.length
+ settings.set "findModeRawQueryList", @rawQueryList unless isIncognitoMode
# should be called whenever rawQuery is modified.
updateFindModeQuery = ->