From 8b8f32b509c0f9d351a52f90bd2632ce510258bb Mon Sep 17 00:00:00 2001 From: "arv@chromium.org" Date: Tue, 4 May 2010 00:52:08 +0000 Subject: Fix race condition in find as you type. BUG=42953 TEST=manual Review URL: http://codereview.chromium.org/1910001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46308 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/resources/bookmark_manager/main.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/resources/bookmark_manager/main.html b/chrome/browser/resources/bookmark_manager/main.html index b025b94..1da1116 100644 --- a/chrome/browser/resources/bookmark_manager/main.html +++ b/chrome/browser/resources/bookmark_manager/main.html @@ -188,16 +188,25 @@ tree.addEventListener('change', function() { /** * Navigates to a bookmark ID. * @param {string} id The ID to navigate to. + * @param {boolean=} opt_updateHashNow Whether to immediately update the + * location.hash. If false then it is updated in a timeout. */ -function navigateTo(id) { - console.info('navigateTo', window.location.hash, id); +function navigateTo(id, opt_updateHashNow) { + console.info('navigateTo', 'from', window.location.hash, 'to', id); // Update the location hash using a timer to prevent reentrancy. This is how // often we add history entries and the time here is a bit arbitrary but was // picked as the smallest time a human perceives as instant. - clearTimeout(navigateTo.timer_); - navigateTo.timer_ = setTimeout(function() { + + function f() { window.location.hash = tree.selectedItem.bookmarkId; - }, 300); + } + + clearTimeout(navigateTo.timer_); + if (opt_updateHashNow) + f(); + else + navigateTo.timer_ = setTimeout(f, 250); + updateParentId(id); } @@ -288,7 +297,8 @@ function setSearch(searchText) { id = tree.selectedItem.bookmarkId; } - navigateTo(id); + // Navigate now and update hash immediately. + navigateTo(id, true); } // Handle the logo button UI. -- cgit v1.1