From 3dc8a03d7271c659139c157bb658795dd21298f9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 11 Nov 2012 13:22:18 +0000 Subject: Remove history entries. When a chrome history entry is removed, remove that entry from our history too. Same when the entire history is removed. --- background_scripts/completion.coffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 25f76c1e..8ab71290 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -365,6 +365,7 @@ HistoryCache = history.sort @compareHistoryByUrl @history = history chrome.history.onVisited.addListener(@onPageVisited.bind(this)) + chrome.history.onVisitRemoved.addListener(@onVisitRemoved.bind(this)) callback(@history) for callback in @callbacks @callbacks = null @@ -383,6 +384,18 @@ HistoryCache = else @history.splice(i, 0, newPage) + # When a page is removed from the chrome history, remove it from the vimium history too. + onVisitRemoved: (toRemove) -> + if toRemove.allHistory + @history = [] + else + toRemove.urls.map (url) => + i = HistoryCache.binarySearch({url:url}, @history, @compareHistoryByUrl) + # TODO (smblott) + # The `i < @history.length` condition below should not be necessary. It can be removed when `binarySearch` is fixed. + if i < @history.length and @history[i].url == url + @history.splice(i, 1) + # Returns the matching index or the closest matching index if the element is not found. That means you # must check the element at the returned index to know whether the element was actually found. # This method is used for quickly searching through our history cache. -- cgit v1.2.3