Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Update focused cell after a cell has been deleted with keyboard short…
Browse files Browse the repository at this point in the history
…cut (mac), closes #2345
  • Loading branch information
IndrekV committed Feb 15, 2018
1 parent 9220150 commit b2f9904
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ui/osx/TogglDesktop/TimeEntryListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ - (void)displayTimeEntryList:(DisplayCommand *)cmd
[viewitems addObject:it];
}
}

NSInteger i = [self.timeEntriesTableView selectedRow];
[self.timeEntriesTableView reloadData];
if (cmd.open)
{
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/ui/osx/TogglDesktop/test2/NSUnstripedTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
}
}

Expand Down

0 comments on commit b2f9904

Please sign in to comment.