Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_popup_model.cc |
| diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc |
| index 588683dc4b96148ec578265f0f47516c8cd3aae8..d683a73c9a35bc8e55d3116686a9aa01f688d4da 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc |
| @@ -122,12 +122,21 @@ void AutocompletePopupModel::SetSelectedLine(size_t line, |
| // that when the edit notifies its controller that something has changed, the |
| // controller can get the correct updated data. |
| // |
| - // NOTE: We should never reach here with no selected line; the same code that |
| - // opened the popup and made it possible to get here should have also set a |
| - // selected line. |
| - CHECK(selected_line_ != kNoMatch); |
| - GURL current_destination(result.match_at(selected_line_).destination_url); |
| - view_->InvalidateLine(selected_line_); |
| + // |selected_line_| could be kNoMatch only when the previously selected line |
| + // has just been deleted. In this case, the |edit_model_| has already been |
| + // reverted to the default match, so we need to use the default match for |
| + // |current_destination|, to make sure |edit_model_| can record it properly. |
| + // This step is necessary because the default match may have been changed if |
| + // the deleted item was the default match. |
| + GURL current_destination; |
| + if (selected_line_ != kNoMatch) { |
| + current_destination = result.match_at(selected_line_).destination_url; |
| + view_->InvalidateLine(selected_line_); |
| + } else { |
| + // We must have a default match if we get here. |
| + CHECK(result.default_match() != result.end()); |
| + current_destination = result.default_match()->destination_url; |
| + } |
| selected_line_ = line; |
| view_->InvalidateLine(selected_line_); |
| @@ -288,6 +297,9 @@ void AutocompletePopupModel::TryDeletingCurrentItem() { |
| // the results have changed. |
| const AutocompleteResult& result = controller_->result(); |
| if (!result.empty()) { |
|
Peter Kasting
2011/01/24 23:25:52
If I'm not mistaken, we can change this conditiona
James Su
2011/01/25 02:24:55
It has an issue for the deleting default match cas
Peter Kasting
2011/01/25 02:36:20
But your code has an opposite problem: If we don't
James Su
2011/01/25 02:51:51
Isn't that guaranteed by above if (match.deletable
Peter Kasting
2011/01/25 04:23:20
Why don't we do this: Add a DCHECK(updated_latest_
James Su
2011/01/25 05:30:11
I just checked the source code, and yes it's proba
|
| + // Set |selected_line_| to kNoMatch to forcely select the line, even if |
|
Peter Kasting
2011/01/24 23:25:52
I think if we change the conditional as I note abo
James Su
2011/01/25 02:24:55
See above.
Peter Kasting
2011/01/25 02:36:20
OK, but I still think this can be done more cleanl
James Su
2011/01/25 02:51:51
Ok I'll do it. It's actually my original approach.
|
| + // the value is not changed at all. |
| + selected_line_ = kNoMatch; |
| // Move the selection to the next choice after the deleted one. |
| // SetSelectedLine() will clamp to take care of the case where we deleted |
| // the last item. |
| @@ -311,6 +323,9 @@ void AutocompletePopupModel::Observe(NotificationType type, |
| kNoMatch : static_cast<size_t>(result->default_match() - result->begin()); |
| // There had better not be a nonempty result set with no default match. |
| CHECK((selected_line_ != kNoMatch) || result->empty()); |
| + // We need to clear |manually_selected_match_|, as |selected_line_| has been |
| + // reverted to the default match. |
|
Peter Kasting
2011/01/24 23:25:52
Nit: I don't think this comment is necessary; it's
James Su
2011/01/25 02:24:55
Done.
|
| + manually_selected_match_.Clear(); |
| // If we're going to trim the window size to no longer include the hovered |
| // line, turn hover off. Practically, this shouldn't happen, but it |
| // doesn't hurt to be defensive. |