[fix] input cursor auto moving to the end

This commit is contained in:
Purp1e
2025-03-13 22:25:06 +08:00
parent 0bd15a80cd
commit ccf9e93382
3 changed files with 42 additions and 18 deletions

View File

@@ -3,10 +3,16 @@ import { Plus, SettingConfig, Switch } from "@icon-park/react"
import { useSnapshot } from "valtio"
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { ToolButton } from "../window/ToolButton"
import { useEffect, useState } from "react"
const LaunchOption = () => {
void toolStore.start()
const { launchOptions, launchIndex } = useSnapshot(toolStore.state)
const [launchOpt, setLaunchOpt] = useState(launchOptions[launchIndex] || "")
useEffect(() => {
setLaunchOpt(launchOptions[launchIndex] || "")
}, [launchIndex, launchOptions])
return (
<Card>
@@ -17,7 +23,7 @@ const LaunchOption = () => {
<CardTool>
{launchOptions.map((option, index) => (
<ToolButton key={index} onClick={() => setLaunchIndex(index)}>
{index+1}
{index + 1}
</ToolButton>
))}
<ToolButton onClick={() => addLaunchOption("")}>
@@ -33,8 +39,12 @@ const LaunchOption = () => {
<CardBody>
<textarea
placeholder="请输入启动选项"
value={launchOptions[launchIndex] || ""}
onChange={(e) => launchIndex !== -1 && setLaunchOption(e.target.value, launchIndex)}
value={launchOpt}
onChange={(e) => {
if (launchIndex < 0 || launchIndex > 10) return
setLaunchOpt(e.target.value)
setLaunchOption(e.target.value, launchIndex)
}}
className="w-full font-mono text-base bg-transparent outline-none resize-none min-h-20"
/>
</CardBody>