fix: fix gemini models list
This commit is contained in:
@ -15,7 +15,7 @@ function useTextSelection(containerRef: React.RefObject<HTMLElement>) {
|
||||
const [selection, setSelection] = useState<{ text: string; x: number; y: number } | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
function onMouseUp() {
|
||||
function readSelection() {
|
||||
const sel = window.getSelection()
|
||||
const text = sel?.toString().trim()
|
||||
if (!text || !containerRef.current) { setSelection(null); return }
|
||||
@ -28,14 +28,23 @@ function useTextSelection(containerRef: React.RefObject<HTMLElement>) {
|
||||
y: rect.top - containerRect.top - 8,
|
||||
})
|
||||
}
|
||||
function onMouseDown(e: MouseEvent) {
|
||||
function onMouseUp() { readSelection() }
|
||||
// On mobile, selectionchange fires after the user lifts their finger
|
||||
function onSelectionChange() {
|
||||
const sel = window.getSelection()
|
||||
if (!sel?.toString().trim()) setSelection(null)
|
||||
else readSelection()
|
||||
}
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
if (!(e.target as Element).closest('[data-context-action]')) setSelection(null)
|
||||
}
|
||||
document.addEventListener('mouseup', onMouseUp)
|
||||
document.addEventListener('mousedown', onMouseDown)
|
||||
document.addEventListener('selectionchange', onSelectionChange)
|
||||
document.addEventListener('pointerdown', onPointerDown)
|
||||
return () => {
|
||||
document.removeEventListener('mouseup', onMouseUp)
|
||||
document.removeEventListener('mousedown', onMouseDown)
|
||||
document.removeEventListener('selectionchange', onSelectionChange)
|
||||
document.removeEventListener('pointerdown', onPointerDown)
|
||||
}
|
||||
}, [containerRef])
|
||||
|
||||
@ -278,11 +287,12 @@ export function Dashboard() {
|
||||
<CardContent>
|
||||
<div ref={summaryRef} className="relative">
|
||||
<SummaryContent content={current.content} />
|
||||
{/* Desktop: floating button above selection */}
|
||||
{textSel && (
|
||||
<button
|
||||
data-context-action
|
||||
onClick={addExcerpt}
|
||||
className="absolute z-10 flex items-center gap-1 rounded-full bg-primary text-primary-foreground text-xs px-2 py-1 shadow-lg hover:bg-primary/90 transition-colors"
|
||||
className="absolute z-10 hidden md:flex items-center gap-1 rounded-full bg-primary text-primary-foreground text-xs px-2 py-1 shadow-lg hover:bg-primary/90 transition-colors"
|
||||
style={{ left: textSel.x, top: textSel.y, transform: 'translate(-50%, -100%)' }}
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
@ -290,6 +300,19 @@ export function Dashboard() {
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{/* Mobile: fixed bottom bar — avoids conflict with native selection menu */}
|
||||
{textSel && (
|
||||
<div className="md:hidden fixed bottom-16 left-0 right-0 z-50 flex justify-center px-4 pointer-events-none">
|
||||
<button
|
||||
data-context-action
|
||||
onClick={addExcerpt}
|
||||
className="pointer-events-auto flex items-center gap-2 rounded-full bg-primary text-primary-foreground text-sm px-4 py-2.5 shadow-xl"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Ajouter au contexte
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-4 italic">
|
||||
Sélectionnez du texte pour l'ajouter au contexte, puis posez une question dans le panneau qui apparaît.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user