in plugin/src/software/aws/toolkits/eclipse/amazonq/providers/assets/ChatWebViewAssetProvider.java [313:364]
private String getPreventEmptyPopupFunction() {
String selector = ".mynah-button" + ".mynah-button-secondary.mynah-button-border" + ".fill-state-always"
+ ".mynah-chat-item-followup-question-option" + ".mynah-ui-clickable-item";
return """
const observer = new MutationObserver((mutations) => {
try {
const selector = '%s';
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1) { // Check if it's an element node
// Check for direct match
if (node.matches && node.matches(selector)) {
attachEventListeners(node);
}
// Check for nested matches
if (node.querySelectorAll) {
const buttons = node.querySelectorAll(selector); // Missing selector parameter
buttons.forEach(attachEventListeners);
}
}
});
});
} catch (error) {
console.error('Error in mutation observer:', error);
}
});
function attachEventListeners(element) {
if (!element || element.dataset.hasListener) return; // Prevent duplicate listeners
const handleMouseOver = function(event) {
const textSpan = this.querySelector('span.mynah-button-label');
if (textSpan && textSpan.scrollWidth <= textSpan.offsetWidth) {
event.stopImmediatePropagation();
event.stopPropagation();
event.preventDefault();
}
};
element.addEventListener('mouseover', handleMouseOver, true);
element.dataset.hasListener = 'true';
}
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
});
""".formatted(selector);
}