Skip to content

Commit d898018

Browse files
authored
Merge pull request #90 from omnivore-app/fix/highlights-order
fix: sort highlights by position percentage if available
2 parents 2e985bd + 0309413 commit d898018

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { DateTime } from 'luxon'
99
import { render } from 'mustache'
1010
import {
1111
Article,
12-
compareHighlightsInFile,
1312
DATE_FORMAT,
13+
HighlightType,
14+
PageType,
15+
compareHighlightsInFile,
1416
escapeQuotationMarks,
1517
formatDate,
1618
getHighlightLocation,
17-
HighlightType,
1819
loadArticles,
1920
loadDeletedArticleSlugs,
20-
PageType,
2121
parseDateTime,
2222
} from './util'
2323

@@ -222,6 +222,13 @@ const fetchOmnivore = async (inBackground = false) => {
222222
if (highlightOrder === HighlightOrder.LOCATION) {
223223
highlights?.sort((a, b) => {
224224
try {
225+
// sort by highlight position percent if available
226+
if (
227+
a.highlightPositionPercent !== undefined &&
228+
b.highlightPositionPercent !== undefined
229+
) {
230+
return a.highlightPositionPercent - b.highlightPositionPercent
231+
}
225232
if (article.pageType === PageType.File) {
226233
// sort by location in file
227234
return compareHighlightsInFile(a, b)

src/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface Highlight {
8686
updatedAt: string
8787
labels?: Label[]
8888
type: HighlightType
89+
highlightPositionPercent?: number
8990
}
9091

9192
export interface HighlightPoint {
@@ -152,6 +153,7 @@ export const loadArticles = async (
152153
annotation
153154
patch
154155
updatedAt
156+
highlightPositionPercent
155157
labels {
156158
name
157159
}

0 commit comments

Comments
 (0)