Skip to content

Commit

Permalink
Merge pull request #76 from codecov/spalmurray/fix-non-virtualized-lines
Browse files Browse the repository at this point in the history
fix: Non-virtualized file lines not targetted by extension
  • Loading branch information
spalmurray-codecov authored Jul 19, 2024
2 parents b9c7f23 + d4c2d72 commit c45cce0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/content/github/file/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
componentsStorageKey,
flagsStorageKey,
lineSelector,
noVirtLineSelector,
} from "./utils/constants";
import {
animateAndAnnotateLines,
Expand Down Expand Up @@ -228,6 +229,7 @@ async function process(metadata: FileMetadata): Promise<void> {

globals.coverageReport = coverageReport;
animateAndAnnotateLines(lineSelector, annotateLine);
animateAndAnnotateLines(noVirtLineSelector, annotateLine);
}

async function promptPastReport(metadata: FileMetadata): Promise<void> {
Expand Down Expand Up @@ -275,6 +277,7 @@ function createCoverageButton() {
const isInactive = codecovButton.getAttribute("data-inactive");
if (isInactive == "true") {
animateAndAnnotateLines(lineSelector, annotateLine);
animateAndAnnotateLines(noVirtLineSelector, annotateLine);
codecovButton.removeAttribute("data-inactive");
codecovButton.style.opacity = "1";
} else {
Expand Down Expand Up @@ -325,7 +328,15 @@ function updateButton(text: string) {
}

function annotateLine(line: HTMLElement) {
const lineNumber = parseInt(line.getAttribute("data-key")!) + 1;
let lineNumber = _.parseInt(line.getAttribute("data-key")!) + 1;
const lineNumberString = line.getAttribute("data-key");
if (lineNumberString) {
lineNumber = _.parseInt(lineNumberString) + 1; // Virtualized lines have data-key="{number - 1}"
} else {
const noVirtLineNumberString = line.getAttribute("id");
if (!noVirtLineNumberString) return;
lineNumber = _.parseInt(noVirtLineNumberString.slice(2)); // Non-virtualized lines have id="LC{number}"
}
// called from "Coverage: N/A" button on-click handler
if (!globals.coverageReport) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/content/github/file/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const lineSelector = ".react-code-line-contents";
export const noVirtLineSelector = ".react-code-line-contents-no-virtualization"
export const flagsStorageKey = "selected_flags";
export const componentsStorageKey = "selected_components";

0 comments on commit c45cce0

Please sign in to comment.