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

Commit 0b248b7

Browse files
committed
Revert "feat: hover overlay positioning in browser extension"
This reverts commit 990c28f.
1 parent 0923e9b commit 0b248b7

File tree

2 files changed

+13
-58
lines changed

2 files changed

+13
-58
lines changed

src/hoverifier.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ interface HoverifierOptions {
6969

7070
fetchHover: HoverFetcher
7171
fetchJumpURL: JumpURLFetcher
72-
73-
containerIsScrollable: boolean
7472
}
7573

7674
/**
@@ -213,7 +211,6 @@ export const createHoverifier = ({
213211
fetchJumpURL,
214212
logTelemetryEvent,
215213
dom,
216-
containerIsScrollable,
217214
}: HoverifierOptions): Hoverifier => {
218215
// Internal state that is not exposed to the caller
219216
// Shared between all hoverified code views
@@ -338,7 +335,7 @@ export const createHoverifier = ({
338335
// with the latest target that came from either a mouseover, click or location change (whatever was the most recent)
339336
withLatestFrom(merge(codeMouseOverTargets, codeClickTargets, jumpTargets)),
340337
map(([{ hoverOverlayElement, scrollElement }, { target }]) =>
341-
calculateOverlayPosition(scrollElement, target, hoverOverlayElement, containerIsScrollable)
338+
calculateOverlayPosition(scrollElement, target, hoverOverlayElement)
342339
)
343340
)
344341
.subscribe(hoverOverlayPosition => {

src/overlay_position.ts

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
*/
55
const BLOB_PADDING_TOP = 8
66

7-
const calculateOverlayPositionWithinScrollable = (
7+
/**
8+
* Calculates the desired position of the hover overlay depending on the container,
9+
* the hover target and the size of the hover overlay
10+
*
11+
* @param scrollable The closest container that is scrollable
12+
* @param target The DOM Node that was hovered
13+
* @param tooltip The DOM Node of the tooltip
14+
*/
15+
export const calculateOverlayPosition = (
816
scrollable: HTMLElement,
917
target: HTMLElement,
1018
tooltip: HTMLElement
@@ -17,68 +25,18 @@ const calculateOverlayPositionWithinScrollable = (
1725
// changes to vertical height if the tooltip is at the edge of the viewport.
1826
const relLeft = targetBound.left - scrollableBounds.left
1927

20-
const scrollTop = scrollable === document.documentElement ? window.pageYOffset : scrollable.scrollTop
21-
2228
// Anchor the tooltip vertically.
2329
const tooltipBound = tooltip.getBoundingClientRect()
24-
const relTop = targetBound.top + scrollTop - scrollableBounds.top
30+
const relTop = targetBound.top + scrollable.scrollTop - scrollableBounds.top
2531
// This is the padding-top of the blob element
2632
let tooltipTop = relTop - (tooltipBound.height - BLOB_PADDING_TOP)
27-
if (tooltipTop - scrollTop < 0) {
33+
if (tooltipTop - scrollable.scrollTop < 0) {
2834
// Tooltip wouldn't be visible from the top, so display it at the
2935
// bottom.
30-
const relBottom = targetBound.bottom + scrollTop - scrollableBounds.top
36+
const relBottom = targetBound.bottom + scrollable.scrollTop - scrollableBounds.top
3137
tooltipTop = relBottom
3238
} else {
3339
tooltipTop -= BLOB_PADDING_TOP
3440
}
3541
return { left: relLeft, top: tooltipTop }
3642
}
37-
38-
const calculateOverlayPositionWithoutScrollable = (
39-
container: HTMLElement,
40-
target: HTMLElement,
41-
tooltip: HTMLElement
42-
): { left: number; top: number } => {
43-
const containerBound = container.getBoundingClientRect()
44-
45-
// Anchor it horizontally, prior to rendering to account for wrapping
46-
// changes to vertical height if the tooltip is at the edge of the viewport.
47-
const targetBound = target.getBoundingClientRect()
48-
const tooltipLeft = targetBound.left - containerBound.left + window.scrollX
49-
50-
// Anchor the tooltip vertically.
51-
const tooltipBound = tooltip.getBoundingClientRect()
52-
const relTop = targetBound.top - containerBound.top + container.offsetTop
53-
54-
let tooltipTop = relTop - tooltipBound.height
55-
if (tooltipTop - window.scrollY < 0) {
56-
// Tooltip wouldn't be visible from the top, so display it at the bottom.
57-
const relBottom = relTop + targetBound.height
58-
tooltipTop = relBottom
59-
}
60-
61-
return { top: tooltipTop, left: tooltipLeft }
62-
}
63-
64-
/**
65-
* Calculates the desired position of the hover overlay depending on the container,
66-
* the hover target and the size of the hover overlay
67-
*
68-
* @param container The container. If the code view is scrollable, it's the scrollable element, otherwise its the codeView itself.
69-
* @param target The DOM Node that was hovered.
70-
* @param tooltip The DOM Node of the tooltip.
71-
* @param isScrollable Whether the code view is scrollable or not.
72-
*/
73-
export const calculateOverlayPosition = (
74-
container: HTMLElement,
75-
target: HTMLElement,
76-
tooltip: HTMLElement,
77-
isScrollable?: boolean
78-
): { left: number; top: number } => {
79-
if (isScrollable) {
80-
return calculateOverlayPositionWithinScrollable(container, target, tooltip)
81-
}
82-
83-
return calculateOverlayPositionWithoutScrollable(container, target, tooltip)
84-
}

0 commit comments

Comments
 (0)