Skip to content

Commit 07f341b

Browse files
committed
Enhance textarea resizing
1 parent 5146aaa commit 07f341b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

popup-page-scripts/popup-page-advanced.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ document.addEventListener('DOMContentLoaded', () => {
6464
selectorConfig.value = JSON.stringify(defaultSelectors, null, 2);
6565
console.log(`Loaded default selectors for ${site}`);
6666
}
67+
68+
// After programmatic value set, resize to content.
69+
if (typeof resizeVerticalTextarea === 'function') {
70+
// If hidden (collapsed), defer until visible via rAF to let layout settle
71+
requestAnimationFrame(() => resizeVerticalTextarea(selectorConfig));
72+
}
6773
} catch (error) {
6874
console.error('Error loading selectors:', error);
6975
showToast('Error loading selectors', 'error');
@@ -130,6 +136,11 @@ document.addEventListener('DOMContentLoaded', () => {
130136
const defaultSelectors = getDefaultSelectorsForSite(websiteSelect.value);
131137
selectorConfig.value = JSON.stringify(defaultSelectors, null, 2);
132138
showToast('Selectors reset to defaults', 'info');
139+
140+
// Ensure textarea fits to new content
141+
if (typeof resizeVerticalTextarea === 'function') {
142+
requestAnimationFrame(() => resizeVerticalTextarea(selectorConfig));
143+
}
133144
} else {
134145
throw new Error('Failed to reset selectors');
135146
}
@@ -162,4 +173,39 @@ document.addEventListener('DOMContentLoaded', () => {
162173
} else {
163174
console.error('Resizer function not found. Ensure popup-page-customButtons.js is loaded first.');
164175
}
176+
177+
// Observe Advanced section expand/collapse to handle hidden measurement issues
178+
if (advancedSection && selectorConfig) {
179+
const onExpanded = () => {
180+
// Wait for paint so display: block takes effect, then measure
181+
requestAnimationFrame(() => {
182+
if (typeof resizeVerticalTextarea === 'function') {
183+
resizeVerticalTextarea(selectorConfig);
184+
}
185+
});
186+
};
187+
const onCollapsed = () => {
188+
// Drop stale inline height so next expand re-measures from CSS baseline
189+
selectorConfig.style.height = 'auto';
190+
};
191+
192+
const mo = new MutationObserver((mutations) => {
193+
for (const m of mutations) {
194+
if (m.type === 'attributes' && m.attributeName === 'class') {
195+
const isExpanded = advancedSection.classList.contains('expanded');
196+
if (isExpanded) {
197+
onExpanded();
198+
} else {
199+
onCollapsed();
200+
}
201+
}
202+
}
203+
});
204+
mo.observe(advancedSection, { attributes: true, attributeFilter: ['class'] });
205+
}
206+
207+
// Also re-fit while user edits (keeps parity with button card logic)
208+
if (selectorConfig && typeof resizeVerticalTextarea === 'function') {
209+
selectorConfig.addEventListener('input', () => resizeVerticalTextarea(selectorConfig));
210+
}
165211
});

0 commit comments

Comments
 (0)