| Index: chrome/browser/autofill/autofill_dialog_controller_mac.mm
|
| diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
|
| index ac17b073353d3131cc1c674b84b8c0febe39bd49..774be09bb51857613c1c1c367e28ba8c70c83013 100644
|
| --- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm
|
| +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
|
| @@ -94,6 +94,14 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map(
|
| // UI.
|
| - (void)preferenceDidChange:(const std::string&)preferenceName;
|
|
|
| +// Adjust the selected index when underlying data changes.
|
| +// Selects the previous row if possible, else current row, else deselect all.
|
| +- (void) adjustSelectionOnDelete:(NSInteger)selectedRow;
|
| +
|
| +// Adjust the selected index when underlying data changes.
|
| +// Selects the current row if possible, else previous row, else deselect all.
|
| +- (void) adjustSelectionOnReload:(NSInteger)selectedRow;
|
| +
|
| // Returns true if |row| is an index to a valid profile in |tableView_|, and
|
| // false otherwise.
|
| - (BOOL)isProfileRow:(NSInteger)row;
|
| @@ -400,15 +408,7 @@ class PreferenceObserver : public NotificationObserver {
|
| }
|
|
|
| // Select the previous row if possible, else current row, else deselect all.
|
| - if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
|
| - [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
|
| - byExtendingSelection:NO];
|
| - } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
|
| - [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
|
| - byExtendingSelection:NO];
|
| - } else {
|
| - [tableView_ deselectAll:self];
|
| - }
|
| + [self adjustSelectionOnDelete:selectedRow];
|
|
|
| // Saving will save to the PDM and the table will refresh when PDM sends
|
| // notification that the underlying model has changed.
|
| @@ -799,6 +799,7 @@ class PreferenceObserver : public NotificationObserver {
|
| iter != creditCards.end(); ++iter)
|
| creditCards_.push_back(**iter);
|
|
|
| + [self adjustSelectionOnReload:[tableView_ selectedRow]];
|
| [tableView_ reloadData];
|
| }
|
|
|
| @@ -815,6 +816,30 @@ class PreferenceObserver : public NotificationObserver {
|
| }
|
| }
|
|
|
| +- (void) adjustSelectionOnDelete:(NSInteger)selectedRow {
|
| + if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
|
| + [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
|
| + byExtendingSelection:NO];
|
| + } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
|
| + [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
|
| + byExtendingSelection:NO];
|
| + } else {
|
| + [tableView_ deselectAll:self];
|
| + }
|
| +}
|
| +
|
| +- (void) adjustSelectionOnReload:(NSInteger)selectedRow {
|
| + if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
|
| + [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
|
| + byExtendingSelection:NO];
|
| + } else if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
|
| + [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
|
| + byExtendingSelection:NO];
|
| + } else {
|
| + [tableView_ deselectAll:self];
|
| + }
|
| +}
|
| +
|
| - (BOOL)isProfileRow:(NSInteger)row {
|
| if (row > 0 && static_cast<size_t>(row) <= profiles_.size())
|
| return YES;
|
|
|