Skip to content

Agent Zero AI framework

Deduplicate file browser store helpers and fix settings indentation

linkliti76dcea4c6a56
diff --git a/tests/test_file_browser_navigation.py b/tests/test_file_browser_navigation.py
index 68c290126..473b133a8 100644
--- a/tests/test_file_browser_navigation.py
+++ b/tests/test_file_browser_navigation.py
@@ -612,11 +612,11 @@ def test_file_browser_history_back_forward_contract() -> None:
assert "this.history.push(this.browser.currentPath);" not in store
assert store.count("this.pushNavHistory(") == 3
- back_block = store[store.index("async navigateBack()"):store.index("async navigateForward()")]
- forward_block = store[store.index("async navigateForward()"):store.index("async navigateToFolder")]
- for block in (back_block, forward_block):
- assert "preserveOnError: true" in block
- assert "if (loaded) {" in block
+ stack_block = store[store.index("async navigateStack("):store.index("async navigateToFolder")]
+ assert "preserveOnError: true" in stack_block
+ assert "if (loaded) {" in stack_block
+ assert 'navigateStack("history", "forwardHistory")' in store
+ assert 'navigateStack("forwardHistory", "history")' in store
destroy_block = store[store.index(" destroy() {"):store.index(" setupFloatingModal(")]
assert "this.forwardHistory = [];" in destroy_block
diff --git a/webui/components/modals/file-browser/file-browser-store.js b/webui/components/modals/file-browser/file-browser-store.js
index 7a62923f9..9a6fc8dc8 100644
--- a/webui/components/modals/file-browser/file-browser-store.js
+++ b/webui/components/modals/file-browser/file-browser-store.js
@@ -647,7 +647,7 @@ const model = {
}
};
- requestAnimationFrame(() => requestAnimationFrame(restore));
+ this.runNextFrame(restore);
},
formatFileSize(size) {
@@ -782,10 +782,12 @@ const model = {
this.scrollPathInputNextFrame(element);
},
+ runNextFrame(callback) {
+ requestAnimationFrame(() => requestAnimationFrame(callback));
+ },
+
scrollPathInputNextFrame(element) {
- requestAnimationFrame(() => requestAnimationFrame(() => {
- this.scrollPathInputToEnd(element);
- }));
+ this.runNextFrame(() => this.scrollPathInputToEnd(element));
},
sweepDetachedPathObservers() {
@@ -999,10 +1001,13 @@ const model = {
}
},
+ absolutizeSuggestionPath(path) {
+ path = String(path || "");
+ return path && !path.startsWith("/") && path !== "$WORK_DIR" ? `/${path}` : path;
+ },
+
async pickPathSuggestion(suggestion) {
- let path = String(suggestion?.path || "");
- if (path && !path.startsWith("/") && path !== "$WORK_DIR") path = `/${path}`;
- this.pathInput = path;
+ this.pathInput = this.absolutizeSuggestionPath(suggestion?.path);
this.pathSuggestions = [];
await this.submitPath();
},
@@ -1019,8 +1024,7 @@ const model = {
if (this.pathSuggestionsHidden || !this.pathSuggestions.length) return false;
const suggestion = this.activePathSuggestion;
if (!suggestion) return false;
- let path = String(suggestion.path || "");
- if (path && !path.startsWith("/") && path !== "$WORK_DIR") path = `/${path}`;
+ const path = this.absolutizeSuggestionPath(suggestion.path);
this.pathInput = path.endsWith("/") ? path : `${path}/`;
this.pathSuggestions = [];
this.updatePathSuggestions(element);
@@ -1031,13 +1035,13 @@ const model = {
if (this.pathSuggestionsHidden || !this.pathSuggestions.length) return false;
const count = this.pathSuggestions.length;
this.pathSuggestionIndex = (this.pathSuggestionIndex + delta + count) % count;
- requestAnimationFrame(() => requestAnimationFrame(() => {
+ this.runNextFrame(() => {
for (const container of document.querySelectorAll(".path-suggestions")) {
if (container.getClientRects().length === 0) continue;
const row = container.querySelectorAll(".path-suggestion")[this.pathSuggestionIndex];
row?.scrollIntoView({ block: "nearest" });
}
- }));
+ });
return true;
},
@@ -1235,12 +1239,7 @@ const model = {
const result = await this.pickerOnConfirm?.(payload);
if (result === false) return;
this.disposeScopedTooltips();
- if (window.isModalOpen?.(FILE_BROWSER_MODAL_PATH)) {
- window.closeModal(FILE_BROWSER_MODAL_PATH);
- } else {
- // In-place picker over a live surface: restore the browser listing.
- await this.restoreBrowserAfterInPlacePicker();
- }
+ await this.closeOrRestorePicker();
} catch (error) {
const message = error?.message || "File selection failed";
if (this.isSaveAsPicker()) this.pickerFilenameError = message;
@@ -1250,13 +1249,17 @@ const model = {
}
},
- cancelPicker() {
+ async cancelPicker() {
this.disposeScopedTooltips();
+ await this.closeOrRestorePicker();
+ },
+
+ async closeOrRestorePicker() {
if (window.isModalOpen?.(FILE_BROWSER_MODAL_PATH)) {
window.closeModal(FILE_BROWSER_MODAL_PATH);
} else {
// In-place picker over a live surface: restore the browser listing.
- this.restoreBrowserAfterInPlacePicker();
+ await this.restoreBrowserAfterInPlacePicker();
}
},
@@ -1517,28 +1520,24 @@ const model = {
this.forwardHistory = [];
},
- async navigateBack() {
- if (!this.history.length) return;
- const targetPath = this.history.pop();
+ async navigateStack(from, to) {
+ if (!this[from].length) return;
+ const targetPath = this[from].pop();
const previousPath = this.browser.currentPath;
const loaded = await this.fetchFiles(targetPath, { preserveOnError: true });
if (loaded) {
- this.forwardHistory.push(previousPath);
+ this[to].push(previousPath);
} else {
- this.history.push(targetPath);
+ this[from].push(targetPath);
}
},
- async navigateForward() {
- if (!this.forwardHistory.length) return;
- const targetPath = this.forwardHistory.pop();
- const previousPath = this.browser.currentPath;
- const loaded = await this.fetchFiles(targetPath, { preserveOnError: true });
- if (loaded) {
- this.history.push(previousPath);
- } else {
- this.forwardHistory.push(targetPath);
- }
+ navigateBack() {
+ return this.navigateStack("history", "forwardHistory");
+ },
+
+ navigateForward() {
+ return this.navigateStack("forwardHistory", "history");
},
async navigateToFolder(path) {
diff --git a/webui/components/settings/file-browser/file-browser-settings.html b/webui/components/settings/file-browser/file-browser-settings.html
index 2e47358fe..c17ac3af2 100644
--- a/webui/components/settings/file-browser/file-browser-settings.html
+++ b/webui/components/settings/file-browser/file-browser-settings.html
@@ -59,7 +59,7 @@
<div class="field-control">
<input id="files-tree-root" type="text" placeholder="/a0" required pattern="/.*" aria-describedby="files-tree-root-description"
:value="$store.fileBrowser.preferences.treeRoot" @change="if ($el.reportValidity()) $store.fileBrowser.saveTreeRoot($el.value)">
- </div>
+ </div>
</div>
</div>
<div class="field">