fix(skill-editor): select only filename stem when renaming files

Use setSelectionRange to exclude the file extension from the initial
selection, matching the behavior of VS Code and Finder.
This commit is contained in:
yyh
2026-02-06 14:27:52 +08:00
parent 799d0c0d0b
commit f0ba739e44

View File

@ -19,8 +19,16 @@ const TreeEditInput = ({ node }: TreeEditInputProps) => {
: t('skillSidebar.fileNamePlaceholder')
useEffect(() => {
inputRef.current?.focus()
inputRef.current?.select()
const input = inputRef.current
if (!input)
return
input.focus()
const name = input.value
const dotIndex = isFolder ? -1 : name.lastIndexOf('.')
if (dotIndex > 0)
input.setSelectionRange(0, dotIndex)
else
input.select()
}, [])
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {