fix: address release review feedback

This commit is contained in:
Julia Nguyen
2026-06-26 16:22:20 -04:00
parent f54eab2725
commit b6ce599b20
4 changed files with 56 additions and 30 deletions
+10 -12
View File
@@ -83,9 +83,10 @@ ProgressRange getPageProgressRange(const std::shared_ptr<Epub>& epub, const int
return {epub->calculateProgress(spineIndex, start), epub->calculateProgress(spineIndex, end)};
}
bool bookmarkMatchesProgress(const BookmarkEntry& bookmark, const SavedProgressPosition& progress,
bool bookmarkMatchesProgress(const BookmarkEntry& bookmark, const int spineIndex, const int page, const int pageCount,
const ProgressRange& pageRange) {
if (bookmark.xpath == progress.xpath) {
if (bookmark.computedSpineIndex == spineIndex && bookmark.computedChapterPageCount == pageCount &&
bookmark.computedChapterProgress == page) {
return true;
}
@@ -1311,10 +1312,12 @@ void EpubReaderActivity::addBookmark() {
const ProgressRange pageRange = getPageProgressRange(epub, currentSpineIndex, currentPage, pageCount);
const size_t bookmarkCountBeforeToggle = cachedBookmarks.size();
cachedBookmarks.erase(
std::remove_if(cachedBookmarks.begin(), cachedBookmarks.end(),
[&](const BookmarkEntry& b) { return bookmarkMatchesProgress(b, progress, pageRange); }),
cachedBookmarks.end());
cachedBookmarks.erase(std::remove_if(cachedBookmarks.begin(), cachedBookmarks.end(),
[&](const BookmarkEntry& b) {
return bookmarkMatchesProgress(b, currentSpineIndex, currentPage, pageCount,
pageRange);
}),
cachedBookmarks.end());
if (cachedBookmarks.size() != bookmarkCountBeforeToggle) {
bookmarkRemoved = true;
currentPageBookmarked = false;
@@ -1353,12 +1356,7 @@ void EpubReaderActivity::updateBookmarkFlag() {
const ProgressRange pageRange =
getPageProgressRange(epub, currentSpineIndex, section->currentPage, section->pageCount);
currentPageBookmarked = std::any_of(cachedBookmarks.begin(), cachedBookmarks.end(), [&](const BookmarkEntry& b) {
if (b.computedSpineIndex == currentSpineIndex && b.computedChapterPageCount == section->pageCount &&
b.computedChapterProgress == section->currentPage) {
return true;
}
const float bp = std::clamp(b.percentage, 0.0f, 1.0f);
return bp + bookmarkProgressEpsilon >= pageRange.start && bp - bookmarkProgressEpsilon <= pageRange.end;
return bookmarkMatchesProgress(b, currentSpineIndex, section->currentPage, section->pageCount, pageRange);
});
}