Skip to content

Commit

Permalink
Merge pull request #784 from d-i-t-a/bugfix/history-on-internal-links
Browse files Browse the repository at this point in the history
fixes reading position in history on internal links
  • Loading branch information
aferditamuriqi authored Feb 17, 2024
2 parents eeadf7c + 154271b commit e7672b5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/modules/history/HistoryModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export class HistoryModule implements ReaderModule {
}

async push(locator: Locator, history: boolean) {
let lastInHistory;
if (history && this.annotator) {
let lastReadingPosition =
(await this.annotator.getLastReadingPosition()) as
Expand All @@ -141,13 +140,24 @@ export class HistoryModule implements ReaderModule {
) {
this.history.push(lastReadingPosition);
this.historyCurrentIndex = this.history.length - 1;
} else {
const lastInHistory = this.history[this.history.length - 1];
if (
(lastInHistory &&
lastInHistory.href !== locator.href &&
lastInHistory.locations !== locator.locations) ||
lastInHistory === undefined
) {
this.history.push(lastReadingPosition);
this.historyCurrentIndex = this.history.length - 1;
}
}
}

if (this.historyCurrentIndex < this.history.length - 1) {
this.history = this.history.slice(0, this.historyCurrentIndex);
}
lastInHistory = this.history[this.history.length - 1];
const lastInHistory = this.history[this.history.length - 1];
if (
(lastInHistory && lastInHistory.href !== locator.href) ||
lastInHistory === undefined
Expand Down

0 comments on commit e7672b5

Please sign in to comment.