From 4a614c79f3e6cce1066e68bb91fda0a3dbec1acb Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 10 Apr 2023 15:36:03 +0800 Subject: [PATCH] fix: sort highlights by position percentage if available --- src/main.ts | 9 +++++++++ src/util.ts | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/main.ts b/src/main.ts index b5ade27..a8f3450 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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); diff --git a/src/util.ts b/src/util.ts index b71a914..8e4e6fd 100644 --- a/src/util.ts +++ b/src/util.ts @@ -88,6 +88,7 @@ export interface Highlight { updatedAt: string; labels?: Label[]; type: HighlightType; + highlightPositionPercent?: number; } export interface HighlightPoint { @@ -157,6 +158,7 @@ export const loadArticles = async ( patch updatedAt type + highlightPositionPercent labels { name }