From b2f9904e8bcd0cb8d08ccd0ffa5b53c568488d4d Mon Sep 17 00:00:00 2001 From: IndrekV Date: Fri, 16 Feb 2018 00:33:39 +0200 Subject: [PATCH] Update focused cell after a cell has been deleted with keyboard shortcut (mac), closes #2345 --- .../TimeEntryListViewController.m | 14 ++++++++++++- .../TogglDesktop/test2/NSUnstripedTableView.m | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/ui/osx/TogglDesktop/TimeEntryListViewController.m b/src/ui/osx/TogglDesktop/TimeEntryListViewController.m index e4635fd6c0..abdc8966bd 100644 --- a/src/ui/osx/TogglDesktop/TimeEntryListViewController.m +++ b/src/ui/osx/TogglDesktop/TimeEntryListViewController.m @@ -203,7 +203,7 @@ - (void)displayTimeEntryList:(DisplayCommand *)cmd [viewitems addObject:it]; } } - + NSInteger i = [self.timeEntriesTableView selectedRow]; [self.timeEntriesTableView reloadData]; if (cmd.open) { @@ -235,6 +235,18 @@ - (void)displayTimeEntryList:(DisplayCommand *)cmd } [self.timeEntriesTableView scrollPoint:scrollOrigin]; } + + // If row was focused before reload we restore that state + NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:i]; + + [self.timeEntriesTableView selectRowIndexes:indexSet byExtendingSelection:NO]; + TimeEntryCell *cell = [self getSelectedEntryCell:i]; + if (cell != nil) + { + [self clearLastSelectedEntry]; + [cell setFocused]; + [self.timeEntriesTableView scrollRowToVisible:self.lastSelectedRowIndex]; + } } - (void)resetEditPopover:(NSNotification *)notification diff --git a/src/ui/osx/TogglDesktop/test2/NSUnstripedTableView.m b/src/ui/osx/TogglDesktop/test2/NSUnstripedTableView.m index 22a59bddc3..adde5b9128 100644 --- a/src/ui/osx/TogglDesktop/test2/NSUnstripedTableView.m +++ b/src/ui/osx/TogglDesktop/test2/NSUnstripedTableView.m @@ -98,6 +98,7 @@ - (void)deleteEntry if (cell.confrimless_delete) { toggl_delete_time_entry(ctx, [cell.GUID UTF8String]); + [self setFirstRowAsSelected]; return; } NSString *msg = [NSString stringWithFormat:@"Delete time entry \"%@\"?", cell.descriptionTextField.stringValue]; @@ -116,6 +117,25 @@ - (void)deleteEntry NSLog(@"Deleting time entry %@", cell.GUID); toggl_delete_time_entry(ctx, [cell.GUID UTF8String]); + [self setFirstRowAsSelected]; + } +} + +- (void)setFirstRowAsSelected +{ + [self deselectAll:nil]; + if (self.latestSelectedRow > 0) + { + self.latestSelectedRow -= 1; + } + + NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:self.latestSelectedRow]; + [self selectRowIndexes:indexSet byExtendingSelection:NO]; + + TimeEntryCell *cell = [self getSelectedEntryCell]; + if (cell != nil) + { + [cell setFocused]; } }