Skip to content

Commit ada8fd9

Browse files
committed
optimize file rename
1 parent 9efedb1 commit ada8fd9

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"type": "module",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"scripts": {
66
"dev": "vite",
77
"build": "vite build",

src/components/routes/webdav/components/dialog/RenameFile.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {dialogList} from "../../../../../utils/DialogContainer.jsx";
55
import {moveFile} from "../../utils/WebDavUtils.jsx";
66
import useProxyState from "../../../../../hooks/useProxyState.js";
77
import LoadingButton from "../../../../common/base/LoadingButton.jsx";
8+
import {useEffect, useId} from "react";
89

910
function RenameFile({path, name}) {
1011

@@ -13,14 +14,37 @@ function RenameFile({path, name}) {
1314
overwrite: false,
1415
})
1516

17+
18+
const inputId = useId()
19+
1620
const {newName, overwrite} = state;
1721

22+
useEffect(() => {
23+
const input = document.querySelector(`#${inputId}`)
24+
if (!input) {
25+
return
26+
}
27+
input.focus();
28+
29+
const value = input.value;
30+
31+
const dotIndex = value.lastIndexOf('.');
32+
33+
34+
if (dotIndex === -1) {
35+
input.setSelectionRange(0, value.length);
36+
} else {
37+
input.setSelectionRange(0, dotIndex);
38+
}
39+
}, [])
40+
1841

1942
return (
2043
<DialogDiv className={'shadow'}>
2144
<h4 className={'no-select'}>重命名文件</h4>
2245
<div class="content">
2346
<TextField
47+
id={inputId}
2448
label={'文件名称'}
2549
variant={'outlined'}
2650
value={newName}

0 commit comments

Comments
 (0)