Skip to content

Commit

Permalink
Properly order highlight/underline annotations in the same line
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Nov 24, 2023
1 parent 0b695de commit 27c54ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pdf/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,19 @@ export function extractRangeByRects({ structuredText, pageIndex, rects }) {
return range;
}

function getTopMostRectFromPosition(position) {
// Sort the rectangles based on their y2 value in descending order and return the first one
return position?.rects.sort((a, b) => b[2] - a[2])[0];
}

export function getSortIndex(pdfPages, position) {
let { pageIndex } = position;
let offset = 0;
let top = 0;
if (pdfPages[position.pageIndex]) {
let chars = getFlattenedCharsByIndex(pdfPages, position.pageIndex);
let viewBox = pdfPages[position.pageIndex].viewBox;
let rect = getPositionBoundingRect(position);
let rect = getTopMostRectFromPosition(position) || getPositionBoundingRect(position);
offset = chars.length && getClosestOffset(chars, rect) || 0;
let pageHeight = viewBox[3] - viewBox[1];
top = pageHeight - rect[3];
Expand Down

0 comments on commit 27c54ac

Please sign in to comment.