diff --git a/src/core/annotation.js b/src/core/annotation.js index 5520c61e9..e5fa35cda 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -3334,15 +3334,15 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { const vPadding = (lineHeight - fontSize) / 2; const numberOfVisibleLines = Math.floor(totalHeight / lineHeight); - let firstIndex; - if (valueIndices.length === 1) { - const valuePosition = valueIndices[0]; - const indexInPage = valuePosition % numberOfVisibleLines; - firstIndex = valuePosition - indexInPage; - } else { - // If nothing is selected (valueIndice.length === 0), we render - // from the first element. - firstIndex = valueIndices.length ? valueIndices[0] : 0; + let firstIndex = 0; + if (valueIndices.length > 0) { + const minIndex = Math.min(...valueIndices); + const maxIndex = Math.max(...valueIndices); + + firstIndex = Math.max(0, maxIndex - numberOfVisibleLines + 1); + if (firstIndex > minIndex) { + firstIndex = minIndex; + } } const end = Math.min(firstIndex + numberOfVisibleLines + 1, lineCount); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 3a8fe4d15..3ebf63d39 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -596,3 +596,4 @@ !issue14755.pdf !issue16473.pdf !bug1529502.pdf +!issue16500.pdf diff --git a/test/pdfs/issue16500.pdf b/test/pdfs/issue16500.pdf new file mode 100755 index 000000000..82cd2ab86 Binary files /dev/null and b/test/pdfs/issue16500.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 2a187a000..8465574de 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -7694,5 +7694,18 @@ "md5": "4830e765a3d6cb64d39b84de11178f6e", "rounds": 1, "type": "eq" - } + }, + { + "id": "issue16500", + "file": "pdfs/issue16500.pdf", + "md5": "6466546aaa5fcf31235bdf100496705c", + "rounds": 1, + "type": "eq", + "print": true, + "annotationStorage": { + "7R": { + "value": ["Three", "Five"] + } + } + } ]