Skip to content

Commit

Permalink
Preserve current selected article on refreshes
Browse files Browse the repository at this point in the history
- article preservation should not be subject to user's preferences
- remove disturbing notification in OpenReader
- partially reverse commits 3824152 and b31d75d
- reverse 7dec77e which does not solde issue #658 anymore, use another
  trick in mainArticleView's scrollToArticle
  • Loading branch information
barijaona committed Jun 17, 2024
1 parent c398461 commit a220562
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 0 additions & 2 deletions Vienna/Sources/Fetching/OpenReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,6 @@ -(void)starredRequestDone:(NSMutableURLRequest *)request response:(NSURLResponse
[guidArray addObject:guid];
[[refreshedFolder articleFromGuid:guid] markFlagged:YES];
}
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_ArticleListContentChange object:@(
refreshedFolder.itemId)];

[[Database sharedManager] markStarredArticlesFromFolder:refreshedFolder guidArray:guidArray];

Expand Down
29 changes: 8 additions & 21 deletions Vienna/Sources/Main window/ArticleController.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ @implementation ArticleController {
NSString *sortColumnIdentifier;
BackTrackArray *backtrackArray;
BOOL isBacktracking;
BOOL shouldPreserveSelectedArticle;
Article *articleToPreserve;
NSString *guidOfArticleToSelect;
BOOL firstUnreadArticleRequired;
dispatch_queue_t queue;
BOOL requireSelectArticleAfterReload;
}

@synthesize mainArticleView, currentArrayOfArticles, folderArrayOfArticles, articleSortSpecifiers, backtrackArray;
Expand Down Expand Up @@ -147,7 +145,6 @@ -(instancetype)init
context:VNAArticleControllerObserverContext];

queue = dispatch_queue_create("uk.co.opencommunity.vienna2.displayRefresh", DISPATCH_QUEUE_SERIAL);
requireSelectArticleAfterReload = NO;
}
return self;
}
Expand Down Expand Up @@ -431,13 +428,10 @@ -(void)displayNextFolderWithUnread
-(void)displayFolder:(NSInteger)newFolderId
{
if (currentFolderId != newFolderId && newFolderId != 0) {
// Clear all of the articles in the current folder.
// This will reset the scroller position and deselect all.
// Deselect all in current folder.
// Otherwise, the new folder might attempt to preserve selection.
// This can happen with smart folders, which have the same articles as other folders.
self.currentArrayOfArticles = @[];
self.folderArrayOfArticles = @[];
[mainArticleView refreshFolder:VNARefreshRedrawList];
[mainArticleView scrollToArticle:nil];

currentFolderId = newFolderId;
[self reloadArrayOfArticles];
Expand Down Expand Up @@ -477,11 +471,13 @@ -(void)reloadArrayOfArticles
});
Article *article = self.selectedArticle;

if (self->shouldPreserveSelectedArticle) {
// Make sure selectedArticle hasn't changed since reload started.
if (articleToPreserve != nil && articleToPreserve != article) {
if (article != nil && !article.deleted) {
self->articleToPreserve = article;
articleToPreserve = article;
} else {
articleToPreserve = nil;
}
self->shouldPreserveSelectedArticle = NO;
}

[self->mainArticleView refreshFolder:VNARefreshReapplyFilter];
Expand All @@ -494,11 +490,6 @@ -(void)reloadArrayOfArticles
self->firstUnreadArticleRequired = NO;
}

if (self->requireSelectArticleAfterReload) {
[self ensureSelectedArticle];
self->requireSelectArticleAfterReload = NO;
}

// To avoid upsetting the current displayed article after a refresh,
// we check to see if the selected article is the same
// and if it has been updated
Expand Down Expand Up @@ -1008,11 +999,7 @@ -(void)handleArticleListContentChange:(NSNotification *)note
// the article you're current reading can disappear.
// For example, if you're reading in the Unread Articles smart folder.
// So make sure we keep this article around.
if ([Preferences standardPreferences].refreshFrequency > 0
&& [Preferences standardPreferences].markReadInterval > 0.0)
{
shouldPreserveSelectedArticle = YES;
}
articleToPreserve = self.selectedArticle;
[self reloadArrayOfArticles];
}

Expand Down
2 changes: 2 additions & 0 deletions Vienna/Sources/Main window/ArticleListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ -(void)scrollToArticle:(NSString *)guid
}
++rowIndex;
}
} else {
[articleList scrollRowToVisible:0];
}

[articleList deselectAll:self];
Expand Down
2 changes: 2 additions & 0 deletions Vienna/Sources/Main window/UnifiedDisplayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ -(void)scrollToArticle:(NSString *)guid
}
++rowIndex;
}
} else {
[articleList scrollRowToVisible:0];
}

[articleList deselectAll:self];
Expand Down

0 comments on commit a220562

Please sign in to comment.