diff --git a/ui/desktop/src/components/SpellCheckTooltip.tsx b/ui/desktop/src/components/SpellCheckTooltip.tsx index f1ab5e72b4..30f7cac590 100644 --- a/ui/desktop/src/components/SpellCheckTooltip.tsx +++ b/ui/desktop/src/components/SpellCheckTooltip.tsx @@ -25,6 +25,7 @@ const SpellCheckTooltip: React.FC = ({ }) => { const tooltipRef = useRef(null); const [adjustedPosition, setAdjustedPosition] = useState(position); + const [selectedIndex, setSelectedIndex] = useState(0); // Adjust position to keep tooltip within viewport useEffect(() => { @@ -33,22 +34,32 @@ const SpellCheckTooltip: React.FC = ({ const rect = tooltip.getBoundingClientRect(); const viewportWidth = window.innerWidth; const viewportHeight = window.innerHeight; + const tooltipWidth = rect.width || 200; // fallback width + const tooltipHeight = rect.height || 100; // fallback height let adjustedX = position.x; let adjustedY = position.y; + // Calculate the tooltip's left edge when centered + const tooltipLeftEdge = position.x - (tooltipWidth / 2); + const tooltipRightEdge = position.x + (tooltipWidth / 2); + // Adjust horizontal position if tooltip would overflow - if (position.x + rect.width > viewportWidth) { - adjustedX = viewportWidth - rect.width - 10; - } - if (adjustedX < 10) { - adjustedX = 10; + if (tooltipLeftEdge < 10) { + // If left edge would be cut off, align to left edge with padding + adjustedX = (tooltipWidth / 2) + 10; + } else if (tooltipRightEdge > viewportWidth - 10) { + // If right edge would be cut off, align to right edge with padding + adjustedX = viewportWidth - (tooltipWidth / 2) - 10; } // Adjust vertical position if tooltip would overflow - if (position.y + rect.height > viewportHeight) { - adjustedY = position.y - rect.height - 10; + if (position.y + tooltipHeight + 50 > viewportHeight) { + // Show above the word instead of below + adjustedY = position.y - tooltipHeight - 10; } + + // Ensure tooltip doesn't go above viewport if (adjustedY < 10) { adjustedY = 10; } @@ -59,65 +70,99 @@ const SpellCheckTooltip: React.FC = ({ if (!isVisible) return null; + console.log('🖱️ TOOLTIP COMPONENT: Rendering visible tooltip'); + return (
{/* Header */} -
-
- Misspelled: {misspelledWord} -
+
+ Suggestions for "{misspelledWord}"
{/* Suggestions */} - {suggestions.length > 0 && ( -
-
- Suggestions -
+ {suggestions.length > 0 ? ( +
{suggestions.slice(0, 5).map((suggestion, index) => ( ))}
- )} - - {/* No suggestions message */} - {suggestions.length === 0 && ( -
+ ) : ( +
No suggestions available
)} - {/* Actions */} -
- - + {/* Separator */} +
+ + {/* Additional actions */} + + + + + {/* Keyboard hints */} +
+ Press 1-5 to select • ↑↓ to navigate • Enter to apply • Esc to close
);