Fix mobile input prompt command selection (#148)

* fix mobile selection in suggestion dropdowns

* handle mobile keyboard viewport
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-27 17:35:01 -05:00
1 parent f368a2fa62
commit a3237d7f7f
6 files changed
+61 -6

No files matched your search

@@ -56,7 +56,7 @@ export function CommandSuggestions({
return (
<div
ref={listRef}
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-[30vh] md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-48 md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
>
{filteredCommands.map((command, index) => {
const isSelected = index === selectedIndex
@@ -65,6 +65,11 @@ export function CommandSuggestions({
return (
<button
key={command.name}
onMouseDown={(e) => e.preventDefault()}
onTouchEnd={(e) => {
e.preventDefault()
onSelect(command)
}}
onClick={() => onSelect(command)}
className={`w-full px-3 py-2 text-left transition-colors flex items-center gap-2 ${
isSelected
@@ -50,11 +50,16 @@ export function FileSuggestions({
return (
<div
ref={listRef}
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-[30vh] md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-48 md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
>
{files.map((file, idx) => (
<button
key={file}
onMouseDown={(e) => e.preventDefault()}
onTouchEnd={(e) => {
e.preventDefault()
onSelect(file)
}}
onClick={() => onSelect(file)}
className={`w-full px-3 py-2 text-left transition-colors ${
idx === selectedIndex
@@ -58,11 +58,16 @@ export function MentionSuggestions({
return (
<div
ref={listRef}
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-[30vh] md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-48 md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
>
{items.map((item, idx) => (
<button
key={`${item.type}-${item.value}`}
onMouseDown={(e) => e.preventDefault()}
onTouchEnd={(e) => {
e.preventDefault()
onSelect(item)
}}
onClick={() => onSelect(item)}
className={`w-full px-3 py-2 text-left transition-colors flex items-start gap-2 ${
idx === selectedIndex
@@ -284,6 +284,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
if (textareaRef.current) {
textareaRef.current.focus()
textareaRef.current.setSelectionRange(cleanedTemplate.length, cleanedTemplate.length)
textareaRef.current.scrollTop = textareaRef.current.scrollHeight
}
}, 0)
} else {
@@ -302,6 +303,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
const newCursorPos = beforeCommand.length + command.name.length + 2
textareaRef.current.focus()
textareaRef.current.setSelectionRange(newCursorPos, newCursorPos)
textareaRef.current.scrollTop = textareaRef.current.scrollHeight
}
}, 0)
}
@@ -324,6 +326,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
const newCursorPos = beforeMention.length + item.value.length + 2
textareaRef.current.focus()
textareaRef.current.setSelectionRange(newCursorPos, newCursorPos)
textareaRef.current.scrollTop = textareaRef.current.scrollHeight
}
}, 0)
} else {
@@ -351,6 +354,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
const newCursorPos = beforeMention.length + filename.length + 2
textareaRef.current.focus()
textareaRef.current.setSelectionRange(newCursorPos, newCursorPos)
textareaRef.current.scrollTop = textareaRef.current.scrollHeight
}
}, 0)
}
+28
View File
@@ -0,0 +1,28 @@
import { useState, useEffect } from 'react'
export function useVisualViewport() {
const [keyboardHeight, setKeyboardHeight] = useState(0)
useEffect(() => {
const viewport = window.visualViewport
if (!viewport) return
const update = () => {
const layoutHeight = window.innerHeight
const visualHeight = viewport.height + viewport.offsetTop
const offset = Math.max(0, layoutHeight - visualHeight)
setKeyboardHeight(offset)
}
viewport.addEventListener('resize', update)
viewport.addEventListener('scroll', update)
update()
return () => {
viewport.removeEventListener('resize', update)
viewport.removeEventListener('scroll', update)
}
}, [])
return { keyboardHeight }
}
+11 -3
View File
@@ -23,7 +23,8 @@ import { useModelSelection } from "@/hooks/useModelSelection";
import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts";
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
import { useAutoScroll } from "@/hooks/useAutoScroll";
import { useSwipeBack } from "@/hooks/useMobile";
import { useSwipeBack, useMobile } from "@/hooks/useMobile";
import { useVisualViewport } from "@/hooks/useVisualViewport";
import { useTTS } from "@/hooks/useTTS";
import { useEffect, useRef, useCallback, useMemo } from "react";
import { MessageSkeleton } from "@/components/message/MessageSkeleton";
@@ -73,7 +74,11 @@ export function SessionDetail() {
const { bind: bindSwipe, swipeStyles } = useSwipeBack(handleSwipeBack, {
enabled: !fileBrowserOpen && !modelDialogOpen && !sessionsDialogOpen,
});
const isMobile = useMobile();
const { keyboardHeight } = useVisualViewport();
const inputBottomOffset = isMobile ? keyboardHeight : 0;
useEffect(() => {
return bindSwipe(pageRef.current);
}, [bindSwipe]);
@@ -456,7 +461,10 @@ export function SessionDetail() {
) : null}
</div>
{opcodeUrl && repoDirectory && !isEditingMessage && (
<div className="absolute bottom-0 left-0 right-0 flex justify-center">
<div
className="absolute left-0 right-0 flex justify-center"
style={{ bottom: inputBottomOffset }}
>
<div className="relative w-[94%] md:max-w-4xl">
{hasPromptContent && (
<button