diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 19:18:20 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 19:18:20 +0000 |
commit | 5aa609c52f85584aaf12786dcdffed36059b401f (patch) | |
tree | 8ceb6fd60483df495461c35b96dce7c65f4292a2 /chrome/browser/views | |
parent | 2011cae921b2d88be4b8e4f31197dd8bdd2c56b3 (diff) | |
download | chromium_src-5aa609c52f85584aaf12786dcdffed36059b401f.zip chromium_src-5aa609c52f85584aaf12786dcdffed36059b401f.tar.gz chromium_src-5aa609c52f85584aaf12786dcdffed36059b401f.tar.bz2 |
Landing http://codereview.chromium.org/12502 for sverrir:
Fix selection after deleting cookies. The selection was seemingly random
because the model to view mapping changed when deleting items.
BUG=3692
TEST=Try deleting items in cookies view and make sure selection doesn't jump around unexpectedly.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/options/cookies_view.cc | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index a4cc197..42577fe 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -280,17 +280,24 @@ void CookiesTableView::RemoveSelectedCookies() { // Remove the selected cookies. This iterates over the rows backwards, which // is required when calling RemoveCookies, see bug 2994. - int first_selected_row = -1; + int last_selected_view_row = -1; + int remove_count = 0; for (views::TableView::iterator i = SelectionBegin(); i != SelectionEnd(); ++i) { - int selected_row = *i; - if (first_selected_row == -1) - first_selected_row = selected_row; - cookies_model_->RemoveCookies(selected_row, 1); + int selected_model_row = *i; + ++remove_count; + if (last_selected_view_row == -1) { + // Store the view row since the view to model mapping changes when + // we delete. + last_selected_view_row = model_to_view(selected_model_row); + } + cookies_model_->RemoveCookies(selected_model_row, 1); } - // Keep an element selected - if (RowCount() > 0) - Select(std::min(RowCount() - 1, first_selected_row)); + + // Select the next row after the last row deleted (unless removing last row). + DCHECK(RowCount() > 0 && last_selected_view_row != -1); + Select(view_to_model(std::min(RowCount() - 1, + last_selected_view_row - remove_count + 1))); } void CookiesTableView::OnKeyDown(unsigned short virtual_keycode) { |