[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

@@ -1,33 +1,47 @@
"use client"
import { currentUser, setCsDir, setDir, steamStore } from "@/store/steam"
import { useEffect, useState } from "react"
import { useSnapshot } from "valtio"
export default function Page() {
void steamStore.start()
const steam = useSnapshot(steamStore.state)
const [steamDir, setSteamDir] = useState(steam.dir)
const [cs2Dir, setCs2Dir] = useState(steam.csDir)
useEffect(() => {
setSteamDir(steam.dir)
setCs2Dir(steam.csDir)
}, [steam.dir, steam.csDir])
return (
<div
className="flex flex-col items-center justify-center w-full h-screen gap-6"
data-tauri-drag-region
>
<h1 className="text-4xl font-bold tracking-wide text-zinc-800">
CS工具箱
</h1>
<h1 className="text-4xl font-bold tracking-wide">CS工具箱</h1>
<p></p>
<div className="flex flex-col w-full gap-6 p-5 border rounded-lg bg-white/40">
<div className="flex flex-col w-full gap-2 p-5 border rounded-lg bg-white/40">
<p>Steam所在文件夹</p>
<input
className="px-2 py-1 rounded-lg"
value={steam.dir}
onChange={(e) => setDir(e.target.value)}
className="px-2 py-1 mb-2 rounded-lg"
value={steamDir}
onChange={(e) => {
setSteamDir(e.target.value)
setDir(e.target.value)
}}
/>
<p>CS2所在文件夹</p>
<input
className="px-2 py-1 rounded-lg"
value={steam.csDir}
onChange={(e) => setCsDir(e.target.value)}
className="px-2 py-1 mb-2 rounded-lg"
value={cs2Dir}
onChange={(e) => {
setCs2Dir(e.target.value)
setCsDir(e.target.value)
}}
/>
<p>{currentUser().steamID64}</p>
<p>64SteamID{currentUser().steamID64}</p>
</div>
</div>
)

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>

View File

@@ -49,7 +49,7 @@ export const addLaunchOption = (option: string) => {
}
export const resetToolStore = () => {
toolStore.state.launchOptions = defaultValue.launchOptions
toolStore.state.launchIndex = defaultValue.launchIndex
toolStore.state.powerPlan = defaultValue.powerPlan
setLaunchOptions(defaultValue.launchOptions)
setLaunchIndex(defaultValue.launchIndex)
setPowerPlan(defaultValue.powerPlan)
}