Skip to content

Commit 2382549

Browse files
committed
refactor: reuse getClosestTranscriptAncestor in getTranscriptContextMenuLink
The new getTranscriptContextMenuLink helper (from #3188) duplicated the null/contains guard pattern that getClosestTranscriptAncestor — already defined in the same file — performs. Delegate to the shared helper so the target-element and anchor-ancestor checks stay in one place. Behavior-preserving: getClosestTranscriptAncestor returns null for a null/outside-root element, otherwise element.closest(selector), then null again if the ancestor is outside the transcript root — identical to the original inline guards. All 22 transcriptContextMenu tests continue to pass.
1 parent c1a6bc6 commit 2382549

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/browser/utils/messages/transcriptContextMenu.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ export interface TranscriptContextMenuLinkOptions {
256256
export function getTranscriptContextMenuLink(
257257
options: TranscriptContextMenuLinkOptions
258258
): string | null {
259-
const targetElement = getEventTargetElement(options.target);
260-
if (!targetElement || !options.transcriptRoot.contains(targetElement)) {
261-
return null;
262-
}
263-
264-
const anchor = targetElement.closest("a[href]");
265-
if (!anchor || !options.transcriptRoot.contains(anchor)) {
259+
// Reuse the shared ancestor helper so the null/contains guards for the target
260+
// element and the resolved anchor stay in one place.
261+
const anchor = getClosestTranscriptAncestor(
262+
options.transcriptRoot,
263+
getEventTargetElement(options.target),
264+
"a[href]"
265+
);
266+
if (!anchor) {
266267
return null;
267268
}
268269

0 commit comments

Comments
 (0)