feat: Improve text edit popup focus and cursor placement

This commit is contained in:
ousugo 2025-02-18 00:31:51 +08:00 committed by 亢奋猫
parent 0c13e708b9
commit 3383280726

View File

@ -51,6 +51,17 @@ const PopupContainer: React.FC<Props> = ({ text, textareaProps, modalProps, reso
setTimeout(resizeTextArea, 0) setTimeout(resizeTextArea, 0)
}, []) }, [])
const handleAfterOpenChange = (visible: boolean) => {
if (visible) {
const textArea = textareaRef.current?.resizableTextArea?.textArea
if (textArea) {
textArea.focus()
const length = textArea.value.length
textArea.setSelectionRange(length, length)
}
}
}
TextEditPopup.hide = onCancel TextEditPopup.hide = onCancel
return ( return (
@ -65,6 +76,7 @@ const PopupContainer: React.FC<Props> = ({ text, textareaProps, modalProps, reso
onOk={onOk} onOk={onOk}
onCancel={onCancel} onCancel={onCancel}
afterClose={onClose} afterClose={onClose}
afterOpenChange={handleAfterOpenChange}
centered> centered>
<TextArea <TextArea
ref={textareaRef} ref={textareaRef}