Skip to content

Commit 8a69a63

Browse files
committed
Update file-tree.js
1 parent 33cdc02 commit 8a69a63

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

custom_components/blueprint_studio/www/modules/file-tree.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,12 @@ function createInlineExplorerInput(edit) {
11391139
input.setAttribute("aria-label", edit.mode === "rename" ? "Rename item" : "Create item");
11401140
wrap.appendChild(input);
11411141

1142+
input.addEventListener("input", () => {
1143+
if (state.inlineExplorerEdit === edit) {
1144+
edit.value = input.value;
1145+
}
1146+
});
1147+
11421148
const confirmBtn = document.createElement("button");
11431149
confirmBtn.className = "inline-edit-btn";
11441150
confirmBtn.title = t("modal.confirm_button");
@@ -1173,6 +1179,7 @@ function createInlineExplorerInput(edit) {
11731179

11741180
input.addEventListener("blur", () => {
11751181
window.setTimeout(() => {
1182+
if (!wrap.isConnected) return;
11761183
if (!wrap.contains(document.activeElement) && state.inlineExplorerEdit === edit) {
11771184
cancelInlineExplorerEdit();
11781185
}
@@ -1185,13 +1192,20 @@ function createInlineExplorerInput(edit) {
11851192
function focusInlineExplorerInput() {
11861193
if (!state.inlineExplorerEdit) return;
11871194
window.setTimeout(() => {
1195+
const edit = state.inlineExplorerEdit;
1196+
if (!edit) return;
11881197
const input = elements.fileTree?.querySelector(".inline-edit-input");
11891198
if (!input) return;
1190-
input.focus();
1191-
const value = input.value || "";
1192-
const dotIndex = state.inlineExplorerEdit.type === "file" ? value.lastIndexOf(".") : -1;
1193-
const end = dotIndex > 0 ? dotIndex : value.length;
1194-
input.setSelectionRange(0, end);
1199+
if (document.activeElement !== input) {
1200+
input.focus();
1201+
}
1202+
if (edit.selectOnFocus) {
1203+
edit.selectOnFocus = false;
1204+
const value = input.value || "";
1205+
const dotIndex = edit.type === "file" ? value.lastIndexOf(".") : -1;
1206+
const end = dotIndex > 0 ? dotIndex : value.length;
1207+
input.setSelectionRange(0, end);
1208+
}
11951209
}, 0);
11961210
}
11971211

@@ -1300,6 +1314,7 @@ export function startInlineExplorerCreate(type, parentPath = null) {
13001314
type,
13011315
parentPath: targetParent,
13021316
value: type === "folder" ? "new_folder" : "new_file.yaml",
1317+
selectOnFocus: true,
13031318
};
13041319

13051320
renderFileTree();
@@ -1324,6 +1339,7 @@ export function startInlineExplorerRename(path, isFolder) {
13241339
path,
13251340
parentPath,
13261341
value: path.split("/").pop(),
1342+
selectOnFocus: true,
13271343
};
13281344

13291345
renderFileTree();
@@ -1340,6 +1356,9 @@ async function submitInlineExplorerEdit() {
13401356
if (!edit) return;
13411357

13421358
const input = elements.fileTree?.querySelector(".inline-edit-input");
1359+
if (input && state.inlineExplorerEdit === edit) {
1360+
edit.value = input.value;
1361+
}
13431362
const name = normalizeExplorerName(input?.value, edit.type);
13441363
if (!name) {
13451364
showToast(edit.type === "folder" ? t("toast.please_enter_a_folder_name") : t("toast.please_enter_a_file_name"), "warning");

0 commit comments

Comments
 (0)