Skip to content

Commit

Permalink
fix: sort highlights by position percentage if available
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Apr 10, 2023
1 parent 0d63de8 commit 4a614c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ export default class OmnivorePlugin extends Plugin {
if (highlightOrder === "LOCATION") {
articleHighlights.sort((a, b) => {
try {
// sort by highlight position percent if available
if (
a.highlightPositionPercent !== undefined &&
b.highlightPositionPercent !== undefined
) {
return (
a.highlightPositionPercent - b.highlightPositionPercent
);
}
if (article.pageType === PageType.File) {
// sort by location in file
return compareHighlightsInFile(a, b);
Expand Down
2 changes: 2 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface Highlight {
updatedAt: string;
labels?: Label[];
type: HighlightType;
highlightPositionPercent?: number;
}

export interface HighlightPoint {
Expand Down Expand Up @@ -157,6 +158,7 @@ export const loadArticles = async (
patch
updatedAt
type
highlightPositionPercent
labels {
name
}
Expand Down

0 comments on commit 4a614c7

Please sign in to comment.