From b0ffde36732eee6a6b114927d45ae4d1e7ab0107 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 9 Feb 2015 14:13:44 +0000 Subject: Minor refactoring for find-mode history. --- content_scripts/vimium_frontend.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 06eaf334..d51683d5 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -560,22 +560,25 @@ FindModeHistory = @storage.set findModeRawQueryListIncognito: @rawQueryList chrome.storage.onChanged.addListener (changes, area) => - @rawQueryList = changes[@key].newValue if changes[@key]? + @rawQueryList = changes[@key].newValue if changes[@key] getQuery: (index = 0) -> - @rawQueryList?[index] or "" + @rawQueryList[index] or "" saveQuery: (query) -> if 0 < query.length - @rawQueryList = ([ query ].concat @rawQueryList.filter (q) => q != query)[0..@max] + @rawQueryList = @refreshRawQueryList query, @rawQueryList newSetting = {}; newSetting[@key] = @rawQueryList @storage.set newSetting - # Now, check whether we need to propagte this query to incognito mode too. + # If there are any active incognito-mode tabs, then propagte this query to those tabs too. unless isIncognitoMode @storage.get "findModeRawQueryListIncognito", (items) => if not chrome.runtime.lastError and items.findModeRawQueryListIncognito - rawQueryList = ([ query ].concat items.findModeRawQueryListIncognito.filter (q) => q != query)[0..@max] - @storage.set findModeRawQueryListIncognito: rawQueryList + @storage.set + findModeRawQueryListIncognito: @refreshRawQueryList query, items.findModeRawQueryListIncognito + + refreshRawQueryList: (query, rawQueryList) -> + ([ query ].concat rawQueryList.filter (q) => q != query)[0..@max] # should be called whenever rawQuery is modified. updateFindModeQuery = -> -- cgit v1.2.3