diff --git a/packages/app/e2e/mobile/agent-device/native-composer-command-selection.ios.ad b/packages/app/e2e/mobile/agent-device/native-composer-command-selection.ios.ad new file mode 100644 index 0000000000..c02272bf8e --- /dev/null +++ b/packages/app/e2e/mobile/agent-device/native-composer-command-selection.ios.ad @@ -0,0 +1,13 @@ +context platform=ios timeout=60000 retries=0 +# Start in an empty, connected composer with the Claude provider selected. +# COMMAND_ROW must name an inserting command, not an immediate client action. +env COMMAND_ROW="/advisor, Let Claude consult a stronger model at key moments" +env COMMAND_TEXT="/advisor " +open sh.paseo.debug +wait "editable=true" 60000 +fill "editable=true" "/" +wait "label=\"${COMMAND_ROW}\"" 15000 +press "label=\"${COMMAND_ROW}\"" +# Do not type or move the caret: replacement itself must close autocomplete. +wait absent "label=\"${COMMAND_ROW}\"" 3000 +wait "editable=true value=\"${COMMAND_TEXT}\"" 3000 diff --git a/packages/app/src/composer/input/input.tsx b/packages/app/src/composer/input/input.tsx index b0ed623304..0153911627 100644 --- a/packages/app/src/composer/input/input.tsx +++ b/packages/app/src/composer/input/input.tsx @@ -204,7 +204,7 @@ export interface MessageInputProps { onSubmitLoadingPress?: () => void; /** Intercept key press events before default handling. Return true to prevent default. */ onKeyPress?: (event: ComposerKeyPressEvent) => boolean; - /** Reports cursor selection updates from the underlying input. */ + /** Reports selection updates from user input and programmatic replacements. */ onSelectionChange?: (selection: { start: number; end: number }) => void; onFocusChange?: (focused: boolean) => void; onHeightChange?: (height: number) => void; @@ -1468,11 +1468,18 @@ export const MessageInput = forwardRef( if (nextText === "") { textInputRef.current?.reset(); } else { - textInputRef.current?.replaceText(nextText, selection); + textInputRef.current?.replaceText(nextText, selectionRef.current); } onChangeText(nextText); + // iOS does not emit a selection event for a programmatic text replacement. + onSelectionChangeCallback?.(selectionRef.current); }, - [onChangeText, updateComposerHeightForText, updateLiveTextPresence], + [ + onChangeText, + onSelectionChangeCallback, + updateComposerHeightForText, + updateLiveTextPresence, + ], ); useLayoutEffect(