Skip to content

Commit 3191090

Browse files
committed
Detect attribute tooltip change
1 parent a003c24 commit 3191090

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
- Leading newline when adding real-time inputs to empty saved input
2424
- Seed for generators in stress tester not utilizing full 64-bit integer range
25+
- Tooltip not updating when the attribute changes
2526

2627
### Removed
2728

src/webview/Tooltip.svelte

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,31 @@
134134
clearTimeout(showTimeout);
135135
clearTimeout(hideTimeout);
136136
137-
const mutationObserver = new MutationObserver(() => {
138-
// If the target element is no longer in the DOM, hide the tooltip
139-
if (currentTarget && !document.contains(currentTarget)) {
140-
hideTooltip();
137+
const mutationObserver = new MutationObserver((mutations) => {
138+
for (const mutation of mutations) {
139+
if (mutation.type === "childList") {
140+
// If the target element is no longer in the DOM, hide the tooltip
141+
if (currentTarget && !document.contains(currentTarget)) {
142+
hideTooltip();
143+
}
144+
} else if (mutation.type === "attributes" && mutation.attributeName === "data-tooltip") {
145+
if (mutation.target === currentTarget) {
146+
const text = currentTarget.getAttribute("data-tooltip");
147+
if (text) {
148+
tooltipText = text;
149+
} else {
150+
hideTooltip();
151+
}
152+
}
153+
}
141154
}
142155
});
143156
144157
mutationObserver.observe(document.body, {
145158
childList: true,
146159
subtree: true,
160+
attributes: true,
161+
attributeFilter: ["data-tooltip"],
147162
});
148163
149164
// Hide tooltip on window resize

0 commit comments

Comments
 (0)