Skip to content

Commit b47be1a

Browse files
committed
Improve tooltip and scroll indicator management
Adds persistent state for horizontal scroll indicators in PresetManagerDialog to prevent duplicates and ensures proper cleanup. Tooltips are now re-attached after preset changes in PresetAddViewRenderer. TooltipManager now hides tooltips on click events without clearing state, improving tooltip usability.
1 parent 4eaa98d commit b47be1a

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

js/utils/PresetManagerDialog.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class PresetManagerDialog {
5454
this.presetsGrid = null;
5555
this.presetPreviewContainer = null;
5656
this.presetPreviewResizeHandler = null;
57+
this.horizontalScrollState = { indicator: null }; // Persistent state for horizontal scroll indicator
5758

5859
// SearchableDropdown instance
5960
this.searchableDropdown = new SearchableDropdown();
@@ -560,12 +561,11 @@ export class PresetManagerDialog {
560561
// Update column scroll indicators
561562
AspectRatioUtils.updateColumnScrollIndicators(columns);
562563

563-
// Add horizontal scroll indicator
564-
const horizontalScrollState = { indicator: null };
564+
// Add horizontal scroll indicator using persistent state
565565
const updateHorizontalScrollIndicator = AspectRatioUtils.createHorizontalScrollManager(
566566
presetsGrid,
567567
this.presetPreviewContainer,
568-
horizontalScrollState
568+
this.horizontalScrollState // Use persistent state to avoid duplicates
569569
);
570570
updateHorizontalScrollIndicator();
571571

@@ -786,6 +786,14 @@ export class PresetManagerDialog {
786786
this.presetPreviewResizeHandler = null;
787787
}
788788

789+
// Clean up horizontal scroll indicator
790+
if (this.horizontalScrollState && this.horizontalScrollState.indicator) {
791+
if (this.horizontalScrollState.indicator.parentNode) {
792+
this.horizontalScrollState.indicator.parentNode.removeChild(this.horizontalScrollState.indicator);
793+
}
794+
this.horizontalScrollState.indicator = null;
795+
}
796+
789797
// Close SearchableDropdown if it's open
790798
if (this.searchableDropdown) {
791799
this.searchableDropdown.hide();

js/utils/preset-manager/PresetAddViewRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ export class PresetAddViewRenderer {
706706
if (confirm(`Delete custom preset "${preset.name}"?`)) {
707707
this.parentDialog.manager.deletePreset(this.parentDialog.selectedCategory, preset.name);
708708
this.parentDialog.updatePresetPreview();
709+
this.parentDialog.attachTooltips(); // Re-attach tooltips to new DOM elements
709710
}
710711
});
711712

@@ -732,6 +733,7 @@ export class PresetAddViewRenderer {
732733
e.stopPropagation();
733734
this.parentDialog.manager.toggleBuiltInPresetVisibility(this.parentDialog.selectedCategory, preset.name);
734735
this.parentDialog.updatePresetPreview();
736+
this.parentDialog.attachTooltips(); // Re-attach tooltips to new DOM elements
735737
});
736738

737739
return toggleBtn;

js/utils/preset-manager/TooltipManager.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class TooltipManager {
2020
this.handleMouseEnter = this.handleMouseEnter.bind(this);
2121
this.handleMouseLeave = this.handleMouseLeave.bind(this);
2222
this.handleMouseMove = this.handleMouseMove.bind(this);
23+
this.handleClick = this.handleClick.bind(this);
2324
}
2425

2526
/**
@@ -88,6 +89,7 @@ export class TooltipManager {
8889
element.addEventListener('mouseenter', this.handleMouseEnter);
8990
element.addEventListener('mouseleave', this.handleMouseLeave);
9091
element.addEventListener('mousemove', this.handleMouseMove);
92+
element.addEventListener('click', this.handleClick); // Hide tooltip on click without clearing state
9193
}
9294

9395
/**
@@ -100,6 +102,7 @@ export class TooltipManager {
100102
element.removeEventListener('mouseenter', this.handleMouseEnter);
101103
element.removeEventListener('mouseleave', this.handleMouseLeave);
102104
element.removeEventListener('mousemove', this.handleMouseMove);
105+
element.removeEventListener('click', this.handleClick);
103106
}
104107

105108
/**
@@ -152,6 +155,22 @@ export class TooltipManager {
152155
}
153156
}
154157

158+
/**
159+
* Handles click event - hides tooltip without clearing currentTarget
160+
* @param {MouseEvent} e - Mouse event
161+
*/
162+
handleClick(e) {
163+
// Clear timer
164+
if (this.tooltipTimer) {
165+
clearTimeout(this.tooltipTimer);
166+
this.tooltipTimer = null;
167+
}
168+
169+
// Hide tooltip but don't clear currentTarget
170+
// This allows tooltips to work on subsequent elements
171+
this.hideTooltip();
172+
}
173+
155174
/**
156175
* Gets tooltip text for an element
157176
* @param {HTMLElement} element - Element to get tooltip for

0 commit comments

Comments
 (0)