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

View File

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

View File

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