Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 99e53e9

Browse files
committed
fix(highlight): account for +/- indicator on diff pages
Before the hover range highlighting was off by one
1 parent cf6635a commit 99e53e9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/token_position.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,22 @@ export const getCodeElementsInRange = ({
331331
*
332332
* @param codeView The code view
333333
* @param position 1-indexed position
334-
* @param options Code-host specific implementations of DOM retrieval functions
334+
* @param domOptions Code-host specific implementations of DOM retrieval functions
335335
* @param part If the code view is a diff view, the part of the diff that the position refers to
336336
*/
337337
export const getTokenAtPosition = (
338338
codeView: HTMLElement,
339-
position: Position,
340-
options: DOMFunctions,
339+
{ line, character }: Position,
340+
{ getCodeElementFromLineNumber, getDiffCodePart }: DOMFunctions,
341341
part?: DiffPart
342342
): HTMLElement | undefined => {
343-
const codeCell = options.getCodeElementFromLineNumber(codeView, position.line, part)
344-
if (!codeCell) {
343+
const codeElement = getCodeElementFromLineNumber(codeView, line, part)
344+
if (!codeElement) {
345345
return undefined
346346
}
347-
348-
return findElementWithOffset(codeCell, position.character)
347+
// On diff pages, account for the +/- indicator
348+
if (getDiffCodePart) {
349+
character++
350+
}
351+
return findElementWithOffset(codeElement, character)
349352
}

0 commit comments

Comments
 (0)