@@ -3,10 +3,15 @@ package com.donut.mixfile.util.file
33import androidx.compose.foundation.layout.fillMaxWidth
44import androidx.compose.material3.OutlinedTextField
55import androidx.compose.material3.Text
6+ import androidx.compose.runtime.LaunchedEffect
67import androidx.compose.runtime.getValue
78import androidx.compose.runtime.mutableStateOf
89import androidx.compose.runtime.setValue
910import androidx.compose.ui.Modifier
11+ import androidx.compose.ui.focus.FocusRequester
12+ import androidx.compose.ui.focus.focusRequester
13+ import androidx.compose.ui.text.TextRange
14+ import androidx.compose.ui.text.input.TextFieldValue
1015import com.donut.mixfile.server.core.objects.FileDataLog
1116import com.donut.mixfile.server.core.objects.MixShareInfo
1217import com.donut.mixfile.server.core.utils.resolveMixShareInfo
@@ -42,26 +47,43 @@ fun FileDataLog.updateDataList(
4247fun FileDataLog.rename (callback : (FileDataLog ) -> Unit = {}) {
4348 var shareInfo = resolveMixShareInfo(shareInfoData) ? : return
4449 MixDialogBuilder (" 重命名文件" ).apply {
45- var name by mutableStateOf(shareInfo.fileName)
50+ var value by mutableStateOf(TextFieldValue (shareInfo.fileName))
51+ val focusRequester = FocusRequester ()
4652 setContent {
53+
54+ LaunchedEffect (Unit ) {
55+ focusRequester.requestFocus()
56+ val text = value.text
57+ val dotIndex = text.lastIndexOf(' .' )
58+ val end = if (dotIndex == - 1 ) text.length else dotIndex
59+
60+ value = value.copy(
61+ selection = TextRange (0 , end)
62+ )
63+ }
64+
4765 OutlinedTextField (
48- value = name ,
66+ value = value ,
4967 onValueChange = {
50- name = it
68+ value = it
5169 },
52- modifier = Modifier .fillMaxWidth(), label = {
70+ modifier = Modifier
71+ .focusRequester(focusRequester)
72+ .fillMaxWidth(),
73+ label = {
5374 Text (text = " 输入文件名" )
5475 },
5576 maxLines = 1
5677 )
78+
5779 }
5880 setDefaultNegative()
5981 setPositiveButton(" 确定" ) {
60- if (name .isEmpty()) {
82+ if (value.text .isEmpty()) {
6183 showToast(" 文件名不能为空!" )
6284 return @setPositiveButton
6385 }
64- val sanitizedName = name .sanitizeFileName()
86+ val sanitizedName = value.text .sanitizeFileName()
6587 shareInfo = shareInfo.copy(fileName = sanitizedName)
6688 val renamedLog = copy(
6789 name = sanitizedName,
0 commit comments