@firstpick/pi-package-webui 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pi-webui.mjs +449 -13
- package/lib/trust-boundaries.mjs +2 -0
- package/package.json +2 -2
- package/public/app.js +918 -10
- package/public/index.html +66 -2
- package/public/styles.css +450 -2
- package/tests/fixtures/fake-pi.mjs +59 -3
- package/tests/http-endpoints-harness.test.mjs +212 -2
package/public/app.js
CHANGED
|
@@ -177,6 +177,30 @@ const elements = {
|
|
|
177
177
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
178
178
|
claudeUsageBox: $("#claudeUsageBox"),
|
|
179
179
|
refreshClaudeUsageButton: $("#refreshClaudeUsageButton"),
|
|
180
|
+
fileTreeCwd: $("#fileTreeCwd"),
|
|
181
|
+
fileTreeRoot: $("#fileTreeRoot"),
|
|
182
|
+
fileTreeStatus: $("#fileTreeStatus"),
|
|
183
|
+
fileTreeRefreshButton: $("#fileTreeRefreshButton"),
|
|
184
|
+
fileTreeSearchInput: $("#fileTreeSearchInput"),
|
|
185
|
+
fileTreeSearchClearButton: $("#fileTreeSearchClearButton"),
|
|
186
|
+
fileViewerPane: $("#fileViewerPane"),
|
|
187
|
+
fileViewerResizeHandle: $("#fileViewerResizeHandle"),
|
|
188
|
+
fileViewerTitle: $("#fileViewerTitle"),
|
|
189
|
+
fileViewerMeta: $("#fileViewerMeta"),
|
|
190
|
+
fileViewerOpenDefaultButton: $("#fileViewerOpenDefaultButton"),
|
|
191
|
+
fileViewerSaveButton: $("#fileViewerSaveButton"),
|
|
192
|
+
fileViewerCloseButton: $("#fileViewerCloseButton"),
|
|
193
|
+
fileViewerHelp: $("#fileViewerHelp"),
|
|
194
|
+
fileViewerSourceModeButton: $("#fileViewerSourceModeButton"),
|
|
195
|
+
fileViewerPreviewModeButton: $("#fileViewerPreviewModeButton"),
|
|
196
|
+
fileViewerEditor: $("#fileViewerEditor"),
|
|
197
|
+
fileViewerPreview: $("#fileViewerPreview"),
|
|
198
|
+
fileViewerStatus: $("#fileViewerStatus"),
|
|
199
|
+
fileSelectionBar: $("#fileSelectionBar"),
|
|
200
|
+
fileSelectionSummary: $("#fileSelectionSummary"),
|
|
201
|
+
fileSelectionCommentInput: $("#fileSelectionCommentInput"),
|
|
202
|
+
fileSelectionSendButton: $("#fileSelectionSendButton"),
|
|
203
|
+
fileContextMenu: $("#fileContextMenu"),
|
|
180
204
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
181
205
|
sidePanelExpandButton: $("#sidePanelExpandButton"),
|
|
182
206
|
sidePanelBackdrop: $("#sidePanelBackdrop"),
|
|
@@ -273,6 +297,13 @@ let tabDrafts = new Map();
|
|
|
273
297
|
let tabAttachments = new Map();
|
|
274
298
|
let activeTextAttachmentEditor = null;
|
|
275
299
|
let activeSkillEditor = null;
|
|
300
|
+
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0 };
|
|
301
|
+
let activeFileViewer = null;
|
|
302
|
+
let fileViewerSelection = null;
|
|
303
|
+
let fileContextMenuState = null;
|
|
304
|
+
let fileViewerResizeState = null;
|
|
305
|
+
let fileTreeSearchTimer = null;
|
|
306
|
+
let fileTreeSearchRequestSerial = 0;
|
|
276
307
|
let tabActivities = new Map();
|
|
277
308
|
let tabSeenCompletionSerials = new Map();
|
|
278
309
|
let streamBubble = null;
|
|
@@ -533,6 +564,11 @@ const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
|
533
564
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
534
565
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
535
566
|
const WORKSPACE_DASHBOARD_STORAGE_KEY = "pi-webui-workspace-dashboard-collapsed";
|
|
567
|
+
const FILE_VIEWER_WIDTH_STORAGE_KEY = "pi-webui-file-viewer-width";
|
|
568
|
+
const FILE_VIEWER_WIDTH_DEFAULT_PX = 520;
|
|
569
|
+
const FILE_VIEWER_WIDTH_MIN_PX = 384;
|
|
570
|
+
const FILE_VIEWER_CONTEXT_RADIUS_LINES = 6;
|
|
571
|
+
const FILE_TREE_ROOT_PATH = "";
|
|
536
572
|
const POINTER_ACTIVATION_SELECTOR = "button, a[href], input, select, textarea, summary, [role='button'], [tabindex]:not([tabindex='-1'])";
|
|
537
573
|
const POINTER_ACTIVATION_RENDER_DEFER_MAX_MS = 1200;
|
|
538
574
|
const PROMPT_HISTORY_LIMIT_PER_TAB = 50;
|
|
@@ -2801,19 +2837,17 @@ async function submitEditRetry({ send = false } = {}) {
|
|
|
2801
2837
|
const forkMessage = await resolveForkMessageForEdit(message, messageIndex, tabContext.tabId);
|
|
2802
2838
|
setEditRetryStatus("Forking session…");
|
|
2803
2839
|
const result = await api("/api/fork", { method: "POST", body: { entryId: forkMessage.entryId }, tabId: tabContext.tabId });
|
|
2804
|
-
|
|
2805
|
-
|
|
2840
|
+
const forkTab = await switchToResponseTab(result);
|
|
2841
|
+
const forkTabId = forkTab?.id || activeTabId;
|
|
2806
2842
|
closeEditRetryDialog();
|
|
2807
|
-
await refreshAll(tabContext);
|
|
2808
|
-
if (!isCurrentTabContext(tabContext)) return;
|
|
2809
2843
|
if (send) {
|
|
2810
|
-
addEvent("forked session; sending edited prompt", "info");
|
|
2811
|
-
await sendPrompt("prompt", editedText, { targetTabId:
|
|
2844
|
+
addEvent("forked session in a new tab; sending edited prompt", "info");
|
|
2845
|
+
await sendPrompt("prompt", editedText, { targetTabId: forkTabId, throwOnError: true });
|
|
2812
2846
|
} else {
|
|
2813
2847
|
elements.promptInput.value = editedText;
|
|
2814
2848
|
resizePromptInput();
|
|
2815
2849
|
focusPromptInput({ defer: true });
|
|
2816
|
-
addEvent("forked session; edited prompt restored in composer", "info");
|
|
2850
|
+
addEvent("forked session in a new tab; edited prompt restored in composer", "info");
|
|
2817
2851
|
}
|
|
2818
2852
|
} catch (error) {
|
|
2819
2853
|
setEditRetryStatus(error.message || String(error), "error");
|
|
@@ -5326,6 +5360,797 @@ function isCurrentTabContext(context) {
|
|
|
5326
5360
|
return !!context && context.tabId === activeTabId && context.generation === activeTabGeneration;
|
|
5327
5361
|
}
|
|
5328
5362
|
|
|
5363
|
+
function normalizeFileTreePath(value = "") {
|
|
5364
|
+
return String(value || "").trim().replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/^\/+/, "").replace(/\/+$/g, "");
|
|
5365
|
+
}
|
|
5366
|
+
|
|
5367
|
+
function fileApiPath(basePath, filePath = "") {
|
|
5368
|
+
const path = normalizeFileTreePath(filePath);
|
|
5369
|
+
if (!path) return basePath;
|
|
5370
|
+
const params = new URLSearchParams({ path });
|
|
5371
|
+
return `${basePath}?${params.toString()}`;
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
function fileParentPath(filePath = "") {
|
|
5375
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5376
|
+
const index = normalized.lastIndexOf("/");
|
|
5377
|
+
return index === -1 ? FILE_TREE_ROOT_PATH : normalized.slice(0, index);
|
|
5378
|
+
}
|
|
5379
|
+
|
|
5380
|
+
function fileDisplayName(path = "") {
|
|
5381
|
+
const normalized = normalizeFileTreePath(path);
|
|
5382
|
+
return normalized ? normalized.split("/").pop() || normalized : ".";
|
|
5383
|
+
}
|
|
5384
|
+
|
|
5385
|
+
function fileEntryIcon(entry = {}) {
|
|
5386
|
+
if (entry.type === "directory") return "▸";
|
|
5387
|
+
if (entry.type === "file") return entry.extension === ".md" || entry.extension === ".markdown" ? "Md" : "TXT";
|
|
5388
|
+
if (entry.type === "error") return "!";
|
|
5389
|
+
return "·";
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
function setFileTreeStatus(message = "", level = "muted") {
|
|
5393
|
+
if (!elements.fileTreeStatus) return;
|
|
5394
|
+
elements.fileTreeStatus.textContent = message;
|
|
5395
|
+
elements.fileTreeStatus.className = `file-tree-status ${level || "muted"}`;
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5398
|
+
function setFileViewerStatus(message = "", level = "muted") {
|
|
5399
|
+
if (!elements.fileViewerStatus) return;
|
|
5400
|
+
elements.fileViewerStatus.textContent = message;
|
|
5401
|
+
elements.fileViewerStatus.className = `file-viewer-status ${level || "muted"}`;
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
function emptyFileTreeState(requestSerial = 0) {
|
|
5405
|
+
return { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0 };
|
|
5406
|
+
}
|
|
5407
|
+
|
|
5408
|
+
function fileTreeSearchQueryText() {
|
|
5409
|
+
return String(elements.fileTreeSearchInput?.value || "").trim();
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
function fileSearchApiPath(query = "") {
|
|
5413
|
+
const params = new URLSearchParams({ q: query });
|
|
5414
|
+
return `/api/files/search?${params.toString()}`;
|
|
5415
|
+
}
|
|
5416
|
+
|
|
5417
|
+
function fileTreeEntriesStatus(entries = [], { truncated = false, total = entries.length, searchQuery = "" } = {}) {
|
|
5418
|
+
const count = entries.length;
|
|
5419
|
+
if (searchQuery) {
|
|
5420
|
+
if (!count) return `0 matches for “${searchQuery}”.`;
|
|
5421
|
+
const label = count === 1 ? "match" : "matches";
|
|
5422
|
+
return truncated ? `Showing first ${count} ${label} for “${searchQuery}”.` : `${count} ${label} for “${searchQuery}”.`;
|
|
5423
|
+
}
|
|
5424
|
+
return truncated ? `Showing ${count} of ${total || count} entries.` : `${count} item${count === 1 ? "" : "s"}.`;
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
|
+
function updateFileTreeSearchControls() {
|
|
5428
|
+
const query = fileTreeSearchQueryText();
|
|
5429
|
+
if (elements.fileTreeSearchClearButton) {
|
|
5430
|
+
elements.fileTreeSearchClearButton.hidden = !query;
|
|
5431
|
+
elements.fileTreeSearchClearButton.disabled = !query;
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
|
|
5435
|
+
function resetFileTreeState() {
|
|
5436
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5437
|
+
fileTreeSearchTimer = null;
|
|
5438
|
+
fileTreeSearchRequestSerial += 1;
|
|
5439
|
+
fileTreeState = emptyFileTreeState(fileTreeState.requestSerial + 1);
|
|
5440
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5441
|
+
updateFileTreeSearchControls();
|
|
5442
|
+
renderFileTree();
|
|
5443
|
+
}
|
|
5444
|
+
|
|
5445
|
+
function fileEntryByPath(filePath = "") {
|
|
5446
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5447
|
+
if (!normalized) return { name: ".", path: "", type: "directory", directory: true };
|
|
5448
|
+
for (const entries of fileTreeState.entriesByPath.values()) {
|
|
5449
|
+
const found = entries.find((entry) => normalizeFileTreePath(entry.path) === normalized);
|
|
5450
|
+
if (found) return found;
|
|
5451
|
+
}
|
|
5452
|
+
return null;
|
|
5453
|
+
}
|
|
5454
|
+
|
|
5455
|
+
function renderFileTree() {
|
|
5456
|
+
const root = elements.fileTreeRoot;
|
|
5457
|
+
if (!root) return;
|
|
5458
|
+
root.replaceChildren();
|
|
5459
|
+
updateFileTreeSearchControls();
|
|
5460
|
+
if (elements.fileTreeCwd) elements.fileTreeCwd.textContent = fileTreeState.root || latestWorkspace?.displayCwd || activeTab()?.cwd || "";
|
|
5461
|
+
const searchQuery = fileTreeState.searchQuery || fileTreeSearchQueryText();
|
|
5462
|
+
root.classList.toggle("searching", !!searchQuery);
|
|
5463
|
+
if (searchQuery) {
|
|
5464
|
+
if (fileTreeState.searchLoading) {
|
|
5465
|
+
root.append(make("div", "file-tree-loading muted", `Searching for “${searchQuery}”…`));
|
|
5466
|
+
return;
|
|
5467
|
+
}
|
|
5468
|
+
if (!fileTreeState.searchEntries.length) {
|
|
5469
|
+
root.append(make("div", "file-tree-empty muted", `No files or folders match “${searchQuery}”.`));
|
|
5470
|
+
return;
|
|
5471
|
+
}
|
|
5472
|
+
const list = make("ul", "file-tree-list root search-results");
|
|
5473
|
+
list.setAttribute("role", "group");
|
|
5474
|
+
for (const entry of fileTreeState.searchEntries) appendFileSearchEntry(list, entry);
|
|
5475
|
+
root.append(list);
|
|
5476
|
+
return;
|
|
5477
|
+
}
|
|
5478
|
+
const entries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5479
|
+
if (!entries.length) {
|
|
5480
|
+
root.append(make("div", "file-tree-empty muted", fileTreeState.loading.has(FILE_TREE_ROOT_PATH) ? "Loading files…" : "No files loaded."));
|
|
5481
|
+
return;
|
|
5482
|
+
}
|
|
5483
|
+
const list = make("ul", "file-tree-list root");
|
|
5484
|
+
list.setAttribute("role", "group");
|
|
5485
|
+
for (const entry of entries) appendFileTreeEntry(list, entry, 0);
|
|
5486
|
+
root.append(list);
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5489
|
+
function appendFileSearchEntry(parent, entry) {
|
|
5490
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5491
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5492
|
+
const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5493
|
+
item.setAttribute("role", "none");
|
|
5494
|
+
const button = make("button", "file-tree-item file-tree-search-item");
|
|
5495
|
+
button.type = "button";
|
|
5496
|
+
button.dataset.path = path;
|
|
5497
|
+
button.dataset.type = entry.type || "file";
|
|
5498
|
+
button.style.setProperty("--file-tree-depth", "0");
|
|
5499
|
+
button.setAttribute("role", "treeitem");
|
|
5500
|
+
button.title = [path || ".", entry.error || ""].filter(Boolean).join("\n");
|
|
5501
|
+
const label = make("span", "file-tree-search-label");
|
|
5502
|
+
label.append(
|
|
5503
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5504
|
+
make("span", "file-tree-search-path", path || "."),
|
|
5505
|
+
);
|
|
5506
|
+
button.append(
|
|
5507
|
+
make("span", "file-tree-icon", fileEntryIcon(entry)),
|
|
5508
|
+
label,
|
|
5509
|
+
);
|
|
5510
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5511
|
+
else if (entry.type && entry.type !== "directory") button.append(make("span", "file-tree-kind", entry.type));
|
|
5512
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5513
|
+
button.addEventListener("click", () => {
|
|
5514
|
+
fileTreeState.selectedPath = path;
|
|
5515
|
+
renderFileTree();
|
|
5516
|
+
});
|
|
5517
|
+
button.addEventListener("dblclick", (event) => {
|
|
5518
|
+
event.preventDefault();
|
|
5519
|
+
if (isDirectory) revealFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
5520
|
+
else if (entry.type === "file") openFileInViewer(path);
|
|
5521
|
+
});
|
|
5522
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5523
|
+
item.append(button);
|
|
5524
|
+
parent.append(item);
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
async function revealFileTreeEntry(entry = {}) {
|
|
5528
|
+
const targetPath = normalizeFileTreePath(entry.path || "");
|
|
5529
|
+
if (!targetPath && targetPath !== FILE_TREE_ROOT_PATH) return;
|
|
5530
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5531
|
+
const parentPath = isDirectory ? targetPath : fileParentPath(targetPath);
|
|
5532
|
+
clearFileTreeSearch();
|
|
5533
|
+
fileTreeState.selectedPath = targetPath;
|
|
5534
|
+
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH);
|
|
5535
|
+
let currentPath = "";
|
|
5536
|
+
for (const part of parentPath.split("/").filter(Boolean)) {
|
|
5537
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
5538
|
+
fileTreeState.expanded.add(currentPath);
|
|
5539
|
+
renderFileTree();
|
|
5540
|
+
await loadFileTreeDirectory(currentPath);
|
|
5541
|
+
}
|
|
5542
|
+
if (isDirectory) {
|
|
5543
|
+
fileTreeState.expanded.add(targetPath);
|
|
5544
|
+
await loadFileTreeDirectory(targetPath);
|
|
5545
|
+
}
|
|
5546
|
+
fileTreeState.selectedPath = targetPath;
|
|
5547
|
+
renderFileTree();
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5550
|
+
function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
5551
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5552
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5553
|
+
const expanded = isDirectory && fileTreeState.expanded.has(path);
|
|
5554
|
+
const loading = isDirectory && fileTreeState.loading.has(path);
|
|
5555
|
+
const item = make("li", `file-tree-node ${entry.type || "file"}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5556
|
+
item.setAttribute("role", "none");
|
|
5557
|
+
const button = make("button", "file-tree-item");
|
|
5558
|
+
button.type = "button";
|
|
5559
|
+
button.dataset.path = path;
|
|
5560
|
+
button.dataset.type = entry.type || "file";
|
|
5561
|
+
button.style.setProperty("--file-tree-depth", String(depth));
|
|
5562
|
+
button.setAttribute("role", "treeitem");
|
|
5563
|
+
if (isDirectory) button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
5564
|
+
button.title = [path || ".", entry.error || ""].filter(Boolean).join("\n");
|
|
5565
|
+
button.append(
|
|
5566
|
+
make("span", `file-tree-icon ${isDirectory && expanded ? "expanded" : ""}`, loading ? "…" : fileEntryIcon(entry)),
|
|
5567
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5568
|
+
);
|
|
5569
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5570
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5571
|
+
button.addEventListener("click", () => {
|
|
5572
|
+
fileTreeState.selectedPath = path;
|
|
5573
|
+
if (isDirectory) toggleFileTreeDirectory(path);
|
|
5574
|
+
else renderFileTree();
|
|
5575
|
+
});
|
|
5576
|
+
button.addEventListener("dblclick", (event) => {
|
|
5577
|
+
event.preventDefault();
|
|
5578
|
+
if (isDirectory) toggleFileTreeDirectory(path, { force: true });
|
|
5579
|
+
else openFileInViewer(path);
|
|
5580
|
+
});
|
|
5581
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5582
|
+
item.append(button);
|
|
5583
|
+
if (isDirectory && expanded) {
|
|
5584
|
+
const children = fileTreeState.entriesByPath.get(path) || [];
|
|
5585
|
+
const childList = make("ul", "file-tree-list");
|
|
5586
|
+
childList.setAttribute("role", "group");
|
|
5587
|
+
if (loading) childList.append(make("li", "file-tree-loading muted", "Loading…"));
|
|
5588
|
+
else if (!children.length) childList.append(make("li", "file-tree-empty muted", "Empty"));
|
|
5589
|
+
else for (const child of children) appendFileTreeEntry(childList, child, depth + 1);
|
|
5590
|
+
item.append(childList);
|
|
5591
|
+
}
|
|
5592
|
+
parent.append(item);
|
|
5593
|
+
}
|
|
5594
|
+
|
|
5595
|
+
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false } = {}) {
|
|
5596
|
+
const normalized = normalizeFileTreePath(path);
|
|
5597
|
+
if (!force && fileTreeState.entriesByPath.has(normalized)) return fileTreeState.entriesByPath.get(normalized);
|
|
5598
|
+
const tabContext = activeTabContext();
|
|
5599
|
+
if (!tabContext.tabId || fileTreeState.loading.has(normalized)) return [];
|
|
5600
|
+
const serial = ++fileTreeState.requestSerial;
|
|
5601
|
+
fileTreeState.loading.add(normalized);
|
|
5602
|
+
setFileTreeStatus(normalized ? `Loading ${normalized}…` : "Loading workspace files…");
|
|
5603
|
+
renderFileTree();
|
|
5604
|
+
try {
|
|
5605
|
+
const response = await api(fileApiPath("/api/files", normalized), { tabId: tabContext.tabId });
|
|
5606
|
+
if (!isCurrentTabContext(tabContext) || serial < fileTreeState.requestSerial) return [];
|
|
5607
|
+
const data = response.data || {};
|
|
5608
|
+
if (!normalized && data.root && data.root !== fileTreeState.root) {
|
|
5609
|
+
fileTreeState.root = data.root;
|
|
5610
|
+
fileTreeState.entriesByPath.clear();
|
|
5611
|
+
fileTreeState.expanded.clear();
|
|
5612
|
+
}
|
|
5613
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5614
|
+
fileTreeState.entriesByPath.set(normalized, entries);
|
|
5615
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length }));
|
|
5616
|
+
return entries;
|
|
5617
|
+
} catch (error) {
|
|
5618
|
+
if (isCurrentTabContext(tabContext)) {
|
|
5619
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5620
|
+
addEvent(`file tree failed: ${error.message || String(error)}`, "error");
|
|
5621
|
+
}
|
|
5622
|
+
return [];
|
|
5623
|
+
} finally {
|
|
5624
|
+
fileTreeState.loading.delete(normalized);
|
|
5625
|
+
if (isCurrentTabContext(tabContext)) renderFileTree();
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
|
|
5629
|
+
function clearFileTreeSearch({ focus = false } = {}) {
|
|
5630
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5631
|
+
fileTreeSearchTimer = null;
|
|
5632
|
+
fileTreeSearchRequestSerial += 1;
|
|
5633
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5634
|
+
fileTreeState.searchQuery = "";
|
|
5635
|
+
fileTreeState.searchEntries = [];
|
|
5636
|
+
fileTreeState.searchLoading = false;
|
|
5637
|
+
fileTreeState.searchTruncated = false;
|
|
5638
|
+
fileTreeState.searchTotal = 0;
|
|
5639
|
+
updateFileTreeSearchControls();
|
|
5640
|
+
const rootEntries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5641
|
+
setFileTreeStatus(rootEntries.length ? fileTreeEntriesStatus(rootEntries) : "");
|
|
5642
|
+
renderFileTree();
|
|
5643
|
+
if (focus) elements.fileTreeSearchInput?.focus();
|
|
5644
|
+
}
|
|
5645
|
+
|
|
5646
|
+
async function runFileTreeSearch() {
|
|
5647
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5648
|
+
fileTreeSearchTimer = null;
|
|
5649
|
+
const query = fileTreeSearchQueryText();
|
|
5650
|
+
fileTreeSearchRequestSerial += 1;
|
|
5651
|
+
const serial = fileTreeSearchRequestSerial;
|
|
5652
|
+
if (!query) {
|
|
5653
|
+
clearFileTreeSearch();
|
|
5654
|
+
return [];
|
|
5655
|
+
}
|
|
5656
|
+
const tabContext = activeTabContext();
|
|
5657
|
+
if (!tabContext.tabId) return [];
|
|
5658
|
+
fileTreeState.searchQuery = query;
|
|
5659
|
+
fileTreeState.searchLoading = true;
|
|
5660
|
+
fileTreeState.searchEntries = [];
|
|
5661
|
+
fileTreeState.searchTruncated = false;
|
|
5662
|
+
fileTreeState.searchTotal = 0;
|
|
5663
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5664
|
+
renderFileTree();
|
|
5665
|
+
try {
|
|
5666
|
+
const response = await api(fileSearchApiPath(query), { tabId: tabContext.tabId });
|
|
5667
|
+
if (!isCurrentTabContext(tabContext) || serial !== fileTreeSearchRequestSerial) return [];
|
|
5668
|
+
const data = response.data || {};
|
|
5669
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5670
|
+
if (data.root) fileTreeState.root = data.root;
|
|
5671
|
+
fileTreeState.searchQuery = data.query || query;
|
|
5672
|
+
fileTreeState.searchEntries = entries;
|
|
5673
|
+
fileTreeState.searchLoading = false;
|
|
5674
|
+
fileTreeState.searchTruncated = !!data.truncated;
|
|
5675
|
+
fileTreeState.searchTotal = Number(data.total || entries.length) || entries.length;
|
|
5676
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length, searchQuery: fileTreeState.searchQuery }), entries.length ? "success" : "muted");
|
|
5677
|
+
return entries;
|
|
5678
|
+
} catch (error) {
|
|
5679
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) {
|
|
5680
|
+
fileTreeState.searchLoading = false;
|
|
5681
|
+
fileTreeState.searchEntries = [];
|
|
5682
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5683
|
+
addEvent(`file search failed: ${error.message || String(error)}`, "error");
|
|
5684
|
+
}
|
|
5685
|
+
return [];
|
|
5686
|
+
} finally {
|
|
5687
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) renderFileTree();
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
function scheduleFileTreeSearch(delay = 180) {
|
|
5692
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5693
|
+
const query = fileTreeSearchQueryText();
|
|
5694
|
+
updateFileTreeSearchControls();
|
|
5695
|
+
if (!query) {
|
|
5696
|
+
clearFileTreeSearch();
|
|
5697
|
+
return;
|
|
5698
|
+
}
|
|
5699
|
+
fileTreeSearchRequestSerial += 1;
|
|
5700
|
+
fileTreeState.searchQuery = query;
|
|
5701
|
+
fileTreeState.searchLoading = true;
|
|
5702
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5703
|
+
renderFileTree();
|
|
5704
|
+
fileTreeSearchTimer = setTimeout(() => {
|
|
5705
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
5706
|
+
}, delay);
|
|
5707
|
+
}
|
|
5708
|
+
|
|
5709
|
+
async function refreshFileTreeRoot(tabContext = activeTabContext()) {
|
|
5710
|
+
if (!tabContext.tabId || !elements.fileTreeRoot) return;
|
|
5711
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
5712
|
+
if (fileTreeSearchQueryText()) await runFileTreeSearch();
|
|
5713
|
+
else await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true });
|
|
5714
|
+
}
|
|
5715
|
+
|
|
5716
|
+
async function toggleFileTreeDirectory(path = "", { force = false } = {}) {
|
|
5717
|
+
const normalized = normalizeFileTreePath(path);
|
|
5718
|
+
if (!normalized && normalized !== FILE_TREE_ROOT_PATH) return;
|
|
5719
|
+
const currentlyExpanded = fileTreeState.expanded.has(normalized);
|
|
5720
|
+
if (currentlyExpanded && !force) {
|
|
5721
|
+
fileTreeState.expanded.delete(normalized);
|
|
5722
|
+
renderFileTree();
|
|
5723
|
+
return;
|
|
5724
|
+
}
|
|
5725
|
+
fileTreeState.expanded.add(normalized);
|
|
5726
|
+
renderFileTree();
|
|
5727
|
+
await loadFileTreeDirectory(normalized);
|
|
5728
|
+
}
|
|
5729
|
+
|
|
5730
|
+
function closeFileContextMenu() {
|
|
5731
|
+
fileContextMenuState = null;
|
|
5732
|
+
if (elements.fileContextMenu) elements.fileContextMenu.hidden = true;
|
|
5733
|
+
}
|
|
5734
|
+
|
|
5735
|
+
function showFileContextMenu(event, entry) {
|
|
5736
|
+
if (!elements.fileContextMenu) return;
|
|
5737
|
+
event.preventDefault();
|
|
5738
|
+
event.stopPropagation();
|
|
5739
|
+
const path = normalizeFileTreePath(entry?.path || "");
|
|
5740
|
+
fileContextMenuState = { entry: { ...entry, path } };
|
|
5741
|
+
const menu = elements.fileContextMenu;
|
|
5742
|
+
const webui = menu.querySelector('[data-file-menu-action="open-webui"]');
|
|
5743
|
+
if (webui) webui.textContent = entry?.type === "directory" ? "Open in WebUI" : "Open in WebUI";
|
|
5744
|
+
menu.hidden = false;
|
|
5745
|
+
const rect = menu.getBoundingClientRect();
|
|
5746
|
+
const left = Math.min(event.clientX, Math.max(0, window.innerWidth - rect.width - 8));
|
|
5747
|
+
const top = Math.min(event.clientY, Math.max(0, window.innerHeight - rect.height - 8));
|
|
5748
|
+
menu.style.left = `${left}px`;
|
|
5749
|
+
menu.style.top = `${top}px`;
|
|
5750
|
+
}
|
|
5751
|
+
|
|
5752
|
+
function currentFileViewerPath() {
|
|
5753
|
+
return normalizeFileTreePath(activeFileViewer?.path || elements.fileViewerOpenDefaultButton?.dataset.path || "");
|
|
5754
|
+
}
|
|
5755
|
+
|
|
5756
|
+
async function openPathInDefaultEditor(path = currentFileViewerPath()) {
|
|
5757
|
+
const normalized = normalizeFileTreePath(path);
|
|
5758
|
+
if (!normalized) {
|
|
5759
|
+
addEvent("No file is currently open in the WebUI viewer.", "warn");
|
|
5760
|
+
return;
|
|
5761
|
+
}
|
|
5762
|
+
const tabContext = activeTabContext();
|
|
5763
|
+
try {
|
|
5764
|
+
const response = await api("/api/files/open-default", { method: "POST", body: { path: normalized }, tabId: tabContext.tabId });
|
|
5765
|
+
if (isCurrentTabContext(tabContext)) addEvent(`opened ${response.data?.path || normalized || "."} in the default editor`, "info");
|
|
5766
|
+
} catch (error) {
|
|
5767
|
+
if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5771
|
+
function readStoredFileViewerWidth() {
|
|
5772
|
+
try {
|
|
5773
|
+
const width = Number.parseFloat(localStorage.getItem(FILE_VIEWER_WIDTH_STORAGE_KEY) || "");
|
|
5774
|
+
return Number.isFinite(width) && width >= FILE_VIEWER_WIDTH_MIN_PX ? width : null;
|
|
5775
|
+
} catch {
|
|
5776
|
+
return null;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
|
|
5780
|
+
function persistFileViewerWidth(width) {
|
|
5781
|
+
try {
|
|
5782
|
+
localStorage.setItem(FILE_VIEWER_WIDTH_STORAGE_KEY, String(Math.round(width)));
|
|
5783
|
+
} catch {
|
|
5784
|
+
// Ignore storage failures; resizing should still work for this page load.
|
|
5785
|
+
}
|
|
5786
|
+
}
|
|
5787
|
+
|
|
5788
|
+
function fileViewerMaxWidth() {
|
|
5789
|
+
const layout = document.querySelector(".layout");
|
|
5790
|
+
const layoutRect = layout?.getBoundingClientRect?.();
|
|
5791
|
+
const layoutWidth = layoutRect?.width || window.innerWidth || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5792
|
+
const layoutStyle = layout ? getComputedStyle(layout) : null;
|
|
5793
|
+
const gap = Number.parseFloat(layoutStyle?.columnGap || layoutStyle?.gap || "0") || 0;
|
|
5794
|
+
const sidePanelVisible = !document.body.classList.contains("side-panel-collapsed") && elements.sidePanel && getComputedStyle(elements.sidePanel).display !== "none";
|
|
5795
|
+
const sidePanelWidth = sidePanelVisible ? elements.sidePanel.getBoundingClientRect().width : 0;
|
|
5796
|
+
const splitOpen = document.body.classList.contains("terminal-split-open");
|
|
5797
|
+
const primaryMinWidth = splitOpen ? 560 : 320;
|
|
5798
|
+
const gapCount = splitOpen ? (sidePanelVisible ? 3 : 2) : (sidePanelVisible ? 2 : 1);
|
|
5799
|
+
const available = layoutWidth - sidePanelWidth - primaryMinWidth - (gap * gapCount);
|
|
5800
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(Math.floor(layoutWidth * 0.78), Math.floor(available)));
|
|
5801
|
+
}
|
|
5802
|
+
|
|
5803
|
+
function clampFileViewerWidth(width) {
|
|
5804
|
+
const number = Number(width);
|
|
5805
|
+
const max = fileViewerMaxWidth();
|
|
5806
|
+
const fallback = readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5807
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(max, Number.isFinite(number) ? number : fallback));
|
|
5808
|
+
}
|
|
5809
|
+
|
|
5810
|
+
function currentFileViewerWidth() {
|
|
5811
|
+
const width = elements.fileViewerPane?.getBoundingClientRect?.().width;
|
|
5812
|
+
return Number.isFinite(width) && width > 0 ? width : readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
function updateFileViewerResizeHandle(width = currentFileViewerWidth()) {
|
|
5816
|
+
const handle = elements.fileViewerResizeHandle;
|
|
5817
|
+
if (!handle) return;
|
|
5818
|
+
const resizeAvailable = !!activeFileViewer && !isSidePanelOverlayView();
|
|
5819
|
+
handle.hidden = !resizeAvailable;
|
|
5820
|
+
handle.setAttribute("aria-valuemin", String(FILE_VIEWER_WIDTH_MIN_PX));
|
|
5821
|
+
handle.setAttribute("aria-valuemax", String(fileViewerMaxWidth()));
|
|
5822
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
5823
|
+
handle.setAttribute("aria-valuetext", `${Math.round(width)} pixels wide`);
|
|
5824
|
+
}
|
|
5825
|
+
|
|
5826
|
+
function applyFileViewerWidth(width, { persist = false } = {}) {
|
|
5827
|
+
const clamped = clampFileViewerWidth(width);
|
|
5828
|
+
document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(clamped)}px`);
|
|
5829
|
+
updateFileViewerResizeHandle(clamped);
|
|
5830
|
+
if (persist) persistFileViewerWidth(clamped);
|
|
5831
|
+
return clamped;
|
|
5832
|
+
}
|
|
5833
|
+
|
|
5834
|
+
function restoreFileViewerWidthPreference() {
|
|
5835
|
+
const width = readStoredFileViewerWidth();
|
|
5836
|
+
if (width) document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(width)}px`);
|
|
5837
|
+
updateFileViewerResizeHandle(width || FILE_VIEWER_WIDTH_DEFAULT_PX);
|
|
5838
|
+
}
|
|
5839
|
+
|
|
5840
|
+
function beginFileViewerResize(event) {
|
|
5841
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
5842
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
5843
|
+
event.preventDefault();
|
|
5844
|
+
const startWidth = currentFileViewerWidth();
|
|
5845
|
+
fileViewerResizeState = { pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
5846
|
+
document.body.classList.add("file-viewer-resizing");
|
|
5847
|
+
elements.fileViewerResizeHandle?.setPointerCapture?.(event.pointerId);
|
|
5848
|
+
window.addEventListener("pointermove", updateFileViewerResize, { passive: false });
|
|
5849
|
+
window.addEventListener("pointerup", finishFileViewerResize, { passive: false });
|
|
5850
|
+
window.addEventListener("pointercancel", finishFileViewerResize, { passive: false });
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5853
|
+
function updateFileViewerResize(event) {
|
|
5854
|
+
const state = fileViewerResizeState;
|
|
5855
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5856
|
+
event.preventDefault();
|
|
5857
|
+
state.width = applyFileViewerWidth(state.startWidth + (state.startX - event.clientX));
|
|
5858
|
+
}
|
|
5859
|
+
|
|
5860
|
+
function finishFileViewerResize(event) {
|
|
5861
|
+
const state = fileViewerResizeState;
|
|
5862
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5863
|
+
event.preventDefault?.();
|
|
5864
|
+
elements.fileViewerResizeHandle?.releasePointerCapture?.(state.pointerId);
|
|
5865
|
+
window.removeEventListener("pointermove", updateFileViewerResize);
|
|
5866
|
+
window.removeEventListener("pointerup", finishFileViewerResize);
|
|
5867
|
+
window.removeEventListener("pointercancel", finishFileViewerResize);
|
|
5868
|
+
document.body.classList.remove("file-viewer-resizing");
|
|
5869
|
+
applyFileViewerWidth(state.width, { persist: true });
|
|
5870
|
+
fileViewerResizeState = null;
|
|
5871
|
+
}
|
|
5872
|
+
|
|
5873
|
+
function handleFileViewerResizeKeydown(event) {
|
|
5874
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
5875
|
+
const step = event.shiftKey ? 80 : 24;
|
|
5876
|
+
const current = currentFileViewerWidth();
|
|
5877
|
+
let next = current;
|
|
5878
|
+
if (event.key === "ArrowLeft") next = current + step;
|
|
5879
|
+
else if (event.key === "ArrowRight") next = current - step;
|
|
5880
|
+
else if (event.key === "Home") next = FILE_VIEWER_WIDTH_MIN_PX;
|
|
5881
|
+
else if (event.key === "End") next = fileViewerMaxWidth();
|
|
5882
|
+
else return;
|
|
5883
|
+
event.preventDefault();
|
|
5884
|
+
applyFileViewerWidth(next, { persist: true });
|
|
5885
|
+
}
|
|
5886
|
+
|
|
5887
|
+
function syncFileViewerWidthForViewport() {
|
|
5888
|
+
if (!activeFileViewer) {
|
|
5889
|
+
updateFileViewerResizeHandle();
|
|
5890
|
+
return;
|
|
5891
|
+
}
|
|
5892
|
+
if (isSidePanelOverlayView()) {
|
|
5893
|
+
updateFileViewerResizeHandle();
|
|
5894
|
+
return;
|
|
5895
|
+
}
|
|
5896
|
+
applyFileViewerWidth(currentFileViewerWidth());
|
|
5897
|
+
}
|
|
5898
|
+
|
|
5899
|
+
async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
5900
|
+
if (!entry) return;
|
|
5901
|
+
const path = normalizeFileTreePath(entry.path || "");
|
|
5902
|
+
if (entry.type === "directory" || entry.directory === true) {
|
|
5903
|
+
if (fileTreeState.searchQuery || fileTreeSearchQueryText()) return revealFileTreeEntry(entry);
|
|
5904
|
+
fileTreeState.expanded.add(path);
|
|
5905
|
+
await loadFileTreeDirectory(path);
|
|
5906
|
+
return;
|
|
5907
|
+
}
|
|
5908
|
+
await openFileInViewer(path);
|
|
5909
|
+
}
|
|
5910
|
+
|
|
5911
|
+
function setFileViewerMode(mode = "source") {
|
|
5912
|
+
if (!activeFileViewer) return;
|
|
5913
|
+
const nextMode = mode === "preview" && activeFileViewer.language === "markdown" ? "preview" : "source";
|
|
5914
|
+
activeFileViewer.mode = nextMode;
|
|
5915
|
+
updateFileViewerUi();
|
|
5916
|
+
}
|
|
5917
|
+
|
|
5918
|
+
function setFileViewerDirty(dirty) {
|
|
5919
|
+
if (!activeFileViewer) return;
|
|
5920
|
+
activeFileViewer.dirty = !!dirty;
|
|
5921
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !activeFileViewer.dirty;
|
|
5922
|
+
if (activeFileViewer.dirty) setFileViewerStatus("Unsaved file edits.", "warn");
|
|
5923
|
+
}
|
|
5924
|
+
|
|
5925
|
+
function updateFileViewerUi() {
|
|
5926
|
+
const open = !!activeFileViewer;
|
|
5927
|
+
document.body.classList.toggle("file-viewer-open", open);
|
|
5928
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = !open;
|
|
5929
|
+
updateFileViewerResizeHandle();
|
|
5930
|
+
if (!open) return;
|
|
5931
|
+
if (!isSidePanelOverlayView()) applyFileViewerWidth(currentFileViewerWidth());
|
|
5932
|
+
const viewer = activeFileViewer;
|
|
5933
|
+
const isMarkdown = viewer.language === "markdown";
|
|
5934
|
+
const mode = viewer.mode === "preview" && isMarkdown ? "preview" : "source";
|
|
5935
|
+
viewer.mode = mode;
|
|
5936
|
+
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
5937
|
+
if (elements.fileViewerMeta) {
|
|
5938
|
+
const lineCount = textLineCount(viewer.content || "");
|
|
5939
|
+
elements.fileViewerMeta.textContent = [viewer.path, formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`].filter(Boolean).join(" · ");
|
|
5940
|
+
}
|
|
5941
|
+
if (elements.fileViewerSourceModeButton) {
|
|
5942
|
+
elements.fileViewerSourceModeButton.setAttribute("aria-pressed", mode === "source" ? "true" : "false");
|
|
5943
|
+
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
5944
|
+
}
|
|
5945
|
+
if (elements.fileViewerPreviewModeButton) {
|
|
5946
|
+
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
5947
|
+
elements.fileViewerPreviewModeButton.disabled = !isMarkdown;
|
|
5948
|
+
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed", mode === "preview" ? "true" : "false");
|
|
5949
|
+
elements.fileViewerPreviewModeButton.classList.toggle("active", mode === "preview");
|
|
5950
|
+
}
|
|
5951
|
+
if (elements.fileViewerEditor) {
|
|
5952
|
+
elements.fileViewerEditor.hidden = mode !== "source";
|
|
5953
|
+
if (elements.fileViewerEditor.value !== viewer.content) elements.fileViewerEditor.value = viewer.content || "";
|
|
5954
|
+
}
|
|
5955
|
+
if (elements.fileViewerPreview) {
|
|
5956
|
+
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
5957
|
+
if (mode === "preview") renderMarkdown(elements.fileViewerPreview, viewer.content || "");
|
|
5958
|
+
}
|
|
5959
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !viewer.dirty;
|
|
5960
|
+
if (elements.fileViewerOpenDefaultButton) {
|
|
5961
|
+
const viewerPath = normalizeFileTreePath(viewer.path || "");
|
|
5962
|
+
elements.fileViewerOpenDefaultButton.dataset.path = viewerPath;
|
|
5963
|
+
elements.fileViewerOpenDefaultButton.disabled = !viewerPath;
|
|
5964
|
+
}
|
|
5965
|
+
renderFileViewerSelectionBar();
|
|
5966
|
+
}
|
|
5967
|
+
|
|
5968
|
+
function clearFileViewerSelection() {
|
|
5969
|
+
fileViewerSelection = null;
|
|
5970
|
+
renderFileViewerSelectionBar();
|
|
5971
|
+
}
|
|
5972
|
+
|
|
5973
|
+
function selectedTextFromEditor() {
|
|
5974
|
+
const editor = elements.fileViewerEditor;
|
|
5975
|
+
if (!editor || editor.hidden || !activeFileViewer) return null;
|
|
5976
|
+
const start = editor.selectionStart;
|
|
5977
|
+
const end = editor.selectionEnd;
|
|
5978
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return null;
|
|
5979
|
+
return { start, end, text: editor.value.slice(start, end) };
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
function lineColumnForOffset(text, offset) {
|
|
5983
|
+
const prefix = String(text || "").slice(0, Math.max(0, offset));
|
|
5984
|
+
const lines = prefix.split("\n");
|
|
5985
|
+
return { line: lines.length, column: (lines.at(-1) || "").length + 1 };
|
|
5986
|
+
}
|
|
5987
|
+
|
|
5988
|
+
function fileSelectionLineRange(text, start, end) {
|
|
5989
|
+
const startPos = lineColumnForOffset(text, start);
|
|
5990
|
+
const endPos = lineColumnForOffset(text, end);
|
|
5991
|
+
return { startLine: startPos.line, endLine: endPos.line, startColumn: startPos.column, endColumn: endPos.column };
|
|
5992
|
+
}
|
|
5993
|
+
|
|
5994
|
+
function fileSelectionContext(text, start, end, radius = FILE_VIEWER_CONTEXT_RADIUS_LINES) {
|
|
5995
|
+
const value = String(text || "");
|
|
5996
|
+
const lines = value.split("\n");
|
|
5997
|
+
const range = fileSelectionLineRange(value, start, end);
|
|
5998
|
+
const fromLine = Math.max(1, range.startLine - radius);
|
|
5999
|
+
const toLine = Math.min(lines.length, range.endLine + radius);
|
|
6000
|
+
const contextLines = [];
|
|
6001
|
+
for (let line = fromLine; line <= toLine; line += 1) {
|
|
6002
|
+
contextLines.push(`${String(line).padStart(4, " ")}: ${lines[line - 1] || ""}`);
|
|
6003
|
+
}
|
|
6004
|
+
return { ...range, fromLine, toLine, context: contextLines.join("\n") };
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
function updateFileViewerSelectionFromEditor() {
|
|
6008
|
+
if (!activeFileViewer) return;
|
|
6009
|
+
const selected = selectedTextFromEditor();
|
|
6010
|
+
if (!selected || !selected.text.trim()) {
|
|
6011
|
+
clearFileViewerSelection();
|
|
6012
|
+
return;
|
|
6013
|
+
}
|
|
6014
|
+
const context = fileSelectionContext(elements.fileViewerEditor.value || "", selected.start, selected.end);
|
|
6015
|
+
fileViewerSelection = { ...context, ...selected, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6016
|
+
renderFileViewerSelectionBar();
|
|
6017
|
+
}
|
|
6018
|
+
|
|
6019
|
+
function updateFileViewerSelectionFromPreview() {
|
|
6020
|
+
if (!activeFileViewer || elements.fileViewerPreview?.hidden) return;
|
|
6021
|
+
const selection = window.getSelection?.();
|
|
6022
|
+
const preview = elements.fileViewerPreview;
|
|
6023
|
+
if (!preview || !selection?.anchorNode || !selection?.focusNode || !preview.contains(selection.anchorNode) || !preview.contains(selection.focusNode)) return;
|
|
6024
|
+
const text = String(selection.toString?.() || "").trim();
|
|
6025
|
+
if (!text) {
|
|
6026
|
+
clearFileViewerSelection();
|
|
6027
|
+
return;
|
|
6028
|
+
}
|
|
6029
|
+
const content = activeFileViewer.content || "";
|
|
6030
|
+
const start = Math.max(0, content.indexOf(text));
|
|
6031
|
+
const end = start >= 0 ? start + text.length : start;
|
|
6032
|
+
const context = start >= 0
|
|
6033
|
+
? fileSelectionContext(content, start, end)
|
|
6034
|
+
: { startLine: 1, endLine: textLineCount(content), startColumn: 1, endColumn: 1, fromLine: 1, toLine: textLineCount(content), context: content.slice(0, 4000) };
|
|
6035
|
+
fileViewerSelection = { ...context, start, end, text, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6036
|
+
renderFileViewerSelectionBar();
|
|
6037
|
+
}
|
|
6038
|
+
|
|
6039
|
+
function renderFileViewerSelectionBar() {
|
|
6040
|
+
if (!elements.fileSelectionBar) return;
|
|
6041
|
+
const hasSelection = !!fileViewerSelection?.text;
|
|
6042
|
+
elements.fileSelectionBar.hidden = !hasSelection;
|
|
6043
|
+
if (!hasSelection) return;
|
|
6044
|
+
const lineLabel = fileViewerSelection.startLine === fileViewerSelection.endLine
|
|
6045
|
+
? `line ${fileViewerSelection.startLine}`
|
|
6046
|
+
: `lines ${fileViewerSelection.startLine}-${fileViewerSelection.endLine}`;
|
|
6047
|
+
if (elements.fileSelectionSummary) elements.fileSelectionSummary.textContent = `${lineLabel} · ${fileViewerSelection.text.length} chars selected`;
|
|
6048
|
+
}
|
|
6049
|
+
|
|
6050
|
+
function fileSelectionPrompt() {
|
|
6051
|
+
if (!activeFileViewer || !fileViewerSelection?.text) return "";
|
|
6052
|
+
const comment = (elements.fileSelectionCommentInput?.value || "").trim();
|
|
6053
|
+
const selection = fileViewerSelection;
|
|
6054
|
+
const range = selection.startLine === selection.endLine
|
|
6055
|
+
? `line ${selection.startLine}, columns ${selection.startColumn}-${selection.endColumn}`
|
|
6056
|
+
: `lines ${selection.startLine}-${selection.endLine}`;
|
|
6057
|
+
return [
|
|
6058
|
+
`File selection from ${activeFileViewer.path} (${range}).`,
|
|
6059
|
+
comment ? `User comment: ${comment}` : "User comment: <none>",
|
|
6060
|
+
"",
|
|
6061
|
+
"Selected text:",
|
|
6062
|
+
"```",
|
|
6063
|
+
selection.text,
|
|
6064
|
+
"```",
|
|
6065
|
+
"",
|
|
6066
|
+
`Surrounding context (${selection.fromLine}-${selection.toLine}):`,
|
|
6067
|
+
"```",
|
|
6068
|
+
selection.context || selection.text,
|
|
6069
|
+
"```",
|
|
6070
|
+
].join("\n");
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
async function sendFileSelectionToSession() {
|
|
6074
|
+
const prompt = fileSelectionPrompt();
|
|
6075
|
+
if (!prompt) return;
|
|
6076
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = true;
|
|
6077
|
+
try {
|
|
6078
|
+
await sendPrompt("prompt", prompt, { targetTabId: activeTabId, throwOnError: true });
|
|
6079
|
+
if (elements.fileSelectionCommentInput) elements.fileSelectionCommentInput.value = "";
|
|
6080
|
+
setFileViewerStatus("Selection sent to the current Pi session.", "success");
|
|
6081
|
+
} catch (error) {
|
|
6082
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6083
|
+
} finally {
|
|
6084
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = false;
|
|
6085
|
+
}
|
|
6086
|
+
}
|
|
6087
|
+
|
|
6088
|
+
function closeFileViewer() {
|
|
6089
|
+
activeFileViewer = null;
|
|
6090
|
+
clearFileViewerSelection();
|
|
6091
|
+
document.body.classList.remove("file-viewer-open");
|
|
6092
|
+
updateFileViewerResizeHandle();
|
|
6093
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = true;
|
|
6094
|
+
if (elements.fileViewerOpenDefaultButton) elements.fileViewerOpenDefaultButton.dataset.path = "";
|
|
6095
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = "";
|
|
6096
|
+
if (elements.fileViewerPreview) elements.fileViewerPreview.replaceChildren();
|
|
6097
|
+
setFileViewerStatus("");
|
|
6098
|
+
}
|
|
6099
|
+
|
|
6100
|
+
async function openFileInViewer(path = "") {
|
|
6101
|
+
const normalized = normalizeFileTreePath(path);
|
|
6102
|
+
if (!normalized) return;
|
|
6103
|
+
const tabContext = activeTabContext();
|
|
6104
|
+
fileTreeState.selectedPath = normalized;
|
|
6105
|
+
renderFileTree();
|
|
6106
|
+
setFileViewerStatus(`Opening ${normalized}…`);
|
|
6107
|
+
try {
|
|
6108
|
+
const response = await api(fileApiPath("/api/files/content", normalized), { tabId: tabContext.tabId });
|
|
6109
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6110
|
+
const data = response.data || {};
|
|
6111
|
+
activeFileViewer = {
|
|
6112
|
+
path: normalizeFileTreePath(data.path || normalized),
|
|
6113
|
+
name: data.name || fileDisplayName(normalized),
|
|
6114
|
+
content: String(data.content || ""),
|
|
6115
|
+
size: Number(data.size) || 0,
|
|
6116
|
+
mtimeMs: Number(data.mtimeMs) || 0,
|
|
6117
|
+
extension: data.extension || "",
|
|
6118
|
+
language: data.language || "text",
|
|
6119
|
+
mode: data.language === "markdown" ? "preview" : "source",
|
|
6120
|
+
dirty: false,
|
|
6121
|
+
};
|
|
6122
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
6123
|
+
clearFileViewerSelection();
|
|
6124
|
+
updateFileViewerUi();
|
|
6125
|
+
setFileViewerStatus("Opened in WebUI.", "success");
|
|
6126
|
+
} catch (error) {
|
|
6127
|
+
if (isCurrentTabContext(tabContext)) {
|
|
6128
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6129
|
+
addEvent(`file open failed: ${error.message || String(error)}`, "error");
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
|
|
6134
|
+
async function saveActiveFileViewer() {
|
|
6135
|
+
if (!activeFileViewer || !elements.fileViewerEditor) return;
|
|
6136
|
+
const tabContext = activeTabContext();
|
|
6137
|
+
const content = elements.fileViewerEditor.value || "";
|
|
6138
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = true;
|
|
6139
|
+
setFileViewerStatus(`Saving ${activeFileViewer.path}…`);
|
|
6140
|
+
try {
|
|
6141
|
+
const response = await api("/api/files/content", { method: "POST", body: { path: activeFileViewer.path, content, mtimeMs: activeFileViewer.mtimeMs }, tabId: tabContext.tabId });
|
|
6142
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6143
|
+
const data = response.data || {};
|
|
6144
|
+
activeFileViewer = { ...activeFileViewer, ...data, path: normalizeFileTreePath(data.path || activeFileViewer.path), content, dirty: false };
|
|
6145
|
+
updateFileViewerUi();
|
|
6146
|
+
await loadFileTreeDirectory(fileParentPath(activeFileViewer.path), { force: true });
|
|
6147
|
+
setFileViewerStatus("Saved.", "success");
|
|
6148
|
+
} catch (error) {
|
|
6149
|
+
if (isCurrentTabContext(tabContext)) setFileViewerStatus(error.message || String(error), "error");
|
|
6150
|
+
if (activeFileViewer && elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = false;
|
|
6151
|
+
}
|
|
6152
|
+
}
|
|
6153
|
+
|
|
5329
6154
|
function eventTargetsActiveTab(event) {
|
|
5330
6155
|
return !event?.tabId || event.tabId === activeTabId;
|
|
5331
6156
|
}
|
|
@@ -5430,6 +6255,23 @@ function applyResponseTab(response) {
|
|
|
5430
6255
|
return applyTabMetadata(response?.tab || response?.data?.tab);
|
|
5431
6256
|
}
|
|
5432
6257
|
|
|
6258
|
+
function syncResponseTabs(response) {
|
|
6259
|
+
const payload = response?.data || {};
|
|
6260
|
+
if (Array.isArray(payload.tabs)) {
|
|
6261
|
+
tabs = payload.tabs;
|
|
6262
|
+
syncTabMetadata(tabs);
|
|
6263
|
+
}
|
|
6264
|
+
const tab = response?.tab || payload.tab || null;
|
|
6265
|
+
if (tab) applyTabMetadata(tab);
|
|
6266
|
+
return tab;
|
|
6267
|
+
}
|
|
6268
|
+
|
|
6269
|
+
async function switchToResponseTab(response) {
|
|
6270
|
+
const tab = syncResponseTabs(response);
|
|
6271
|
+
if (tab?.id) await switchTab(tab.id);
|
|
6272
|
+
return tab;
|
|
6273
|
+
}
|
|
6274
|
+
|
|
5433
6275
|
function activityForTab(tab) {
|
|
5434
6276
|
if (!tab?.id) return normalizeTabActivity();
|
|
5435
6277
|
return tabActivities.get(tab.id) || setTabActivity(tab.id, tab.activity) || normalizeTabActivity();
|
|
@@ -5785,6 +6627,8 @@ function resetActiveTabUi() {
|
|
|
5785
6627
|
latestWorkspace = null;
|
|
5786
6628
|
latestMessages = [];
|
|
5787
6629
|
latestMessagesSessionKey = "";
|
|
6630
|
+
closeFileViewer();
|
|
6631
|
+
resetFileTreeState();
|
|
5788
6632
|
clearRunIndicatorActivity({ render: false });
|
|
5789
6633
|
statusEntries.clear();
|
|
5790
6634
|
restoreWidgetsForActiveTab();
|
|
@@ -19191,7 +20035,7 @@ async function openNativeSettingsDialog() {
|
|
|
19191
20035
|
showImages: nativeSettingToggle("Show terminal images", settings.showImages !== false, "Native TUI inline image rendering preference.", { label: "TUI", tone: "tui" }),
|
|
19192
20036
|
imageWidth: nativeSettingSelect("Terminal image width", settings.imageWidthCells || 60, SETTINGS_IMAGE_WIDTH_OPTIONS, "Native TUI inline image width in terminal cells.", { label: "TUI", tone: "tui" }),
|
|
19193
20037
|
skillCommands: nativeSettingToggle("Skill commands", settings.enableSkillCommands !== false, "Register skills as /skill:name commands.", { label: "reload", tone: "reload" }),
|
|
19194
|
-
anthropicWarning: nativeSettingToggle("Anthropic
|
|
20038
|
+
anthropicWarning: nativeSettingToggle("Anthropic Agent SDK usage", settings.warnings?.anthropicExtraUsage !== false, "Native TUI setting for the suppressed Anthropic Agent SDK billing-path warning.", { label: "safety", tone: "safety" }),
|
|
19195
20039
|
collapseChangelog: nativeSettingToggle("Collapse changelog", settings.collapseChangelog === true, "Show condensed changelog after updates.", { label: "startup", tone: "startup" }),
|
|
19196
20040
|
quietStartup: nativeSettingToggle("Quiet startup", settings.quietStartup === true, "Disable verbose printing at startup.", { label: "startup", tone: "startup" }),
|
|
19197
20041
|
installTelemetry: nativeSettingToggle("Install telemetry", settings.enableInstallTelemetry !== false, "Send anonymous version/update ping after changelog-detected updates.", { label: "startup", tone: "startup" }),
|
|
@@ -19266,7 +20110,7 @@ async function openNativeForkSelector() {
|
|
|
19266
20110
|
setNativeCommandError("");
|
|
19267
20111
|
try {
|
|
19268
20112
|
const result = await nativeCommandApi("/api/fork", { method: "POST", body: { entryId: item.message.entryId } });
|
|
19269
|
-
|
|
20113
|
+
await switchToResponseTab(result);
|
|
19270
20114
|
const restoredText = result.data?.text || result.data?.result?.text || "";
|
|
19271
20115
|
if (restoredText) {
|
|
19272
20116
|
elements.promptInput.value = restoredText;
|
|
@@ -19275,7 +20119,6 @@ async function openNativeForkSelector() {
|
|
|
19275
20119
|
}
|
|
19276
20120
|
addTransientMessage({ role: "native", title: "/fork", content: result.data?.message || "Forked the current session.", level: "info" });
|
|
19277
20121
|
closeNativeCommandDialog();
|
|
19278
|
-
await refreshAll();
|
|
19279
20122
|
} catch (error) {
|
|
19280
20123
|
setNativeCommandError(error.message || String(error));
|
|
19281
20124
|
}
|
|
@@ -21482,6 +22325,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
21482
22325
|
refreshNaturalConversationMode(tabContext),
|
|
21483
22326
|
refreshStats(tabContext),
|
|
21484
22327
|
refreshWorkspace(tabContext),
|
|
22328
|
+
refreshFileTreeRoot(tabContext),
|
|
21485
22329
|
refreshAppRunners(tabContext),
|
|
21486
22330
|
refreshNativeSettings(tabContext),
|
|
21487
22331
|
refreshNetworkStatus(),
|
|
@@ -22244,10 +23088,13 @@ function handleEvent(event) {
|
|
|
22244
23088
|
case "webui_cwd_changed":
|
|
22245
23089
|
addEvent(`${event.tabTitle || "terminal"} cwd changed to ${event.cwd}`);
|
|
22246
23090
|
setAppRunnerData(event.tabId || activeTabId, { cwd: event.cwd, activeRun: null, runners: [] });
|
|
23091
|
+
closeFileViewer();
|
|
23092
|
+
resetFileTreeState();
|
|
22247
23093
|
renderAppRunnerControls();
|
|
22248
23094
|
renderWidgets();
|
|
22249
23095
|
renderTabs();
|
|
22250
23096
|
refreshTabs().catch((error) => addEvent(error.message, "error"));
|
|
23097
|
+
refreshFileTreeRoot(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
22251
23098
|
refreshAppRunners(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
22252
23099
|
scheduleRefreshFooter();
|
|
22253
23100
|
break;
|
|
@@ -23309,6 +24156,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
23309
24156
|
setFooterThinkingPickerOpen(false);
|
|
23310
24157
|
setFooterBranchPickerOpen(false);
|
|
23311
24158
|
}
|
|
24159
|
+
if (elements.fileContextMenu && !elements.fileContextMenu.hidden && !event.target?.closest?.(".file-context-menu")) {
|
|
24160
|
+
closeFileContextMenu();
|
|
24161
|
+
}
|
|
23312
24162
|
}, { passive: true });
|
|
23313
24163
|
document.addEventListener("pointermove", (event) => {
|
|
23314
24164
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -23503,6 +24353,7 @@ window.addEventListener("online", () => scheduleForegroundReconcile("network onl
|
|
|
23503
24353
|
window.addEventListener("storage", (event) => {
|
|
23504
24354
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
23505
24355
|
});
|
|
24356
|
+
window.addEventListener("resize", syncFileViewerWidthForViewport, { passive: true });
|
|
23506
24357
|
window.addEventListener("keydown", (event) => {
|
|
23507
24358
|
if (event.key !== "Escape") return;
|
|
23508
24359
|
if (event.defaultPrevented) return;
|
|
@@ -23633,6 +24484,62 @@ elements.refreshCodexUsageButton?.addEventListener("click", () => {
|
|
|
23633
24484
|
elements.refreshClaudeUsageButton?.addEventListener("click", () => {
|
|
23634
24485
|
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
23635
24486
|
});
|
|
24487
|
+
elements.fileTreeRefreshButton?.addEventListener("click", () => refreshFileTreeRoot().catch((error) => addEvent(error.message || String(error), "error")));
|
|
24488
|
+
elements.fileTreeSearchInput?.addEventListener("input", () => scheduleFileTreeSearch());
|
|
24489
|
+
elements.fileTreeSearchInput?.addEventListener("keydown", (event) => {
|
|
24490
|
+
if (event.key === "Enter") {
|
|
24491
|
+
event.preventDefault();
|
|
24492
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
24493
|
+
} else if (event.key === "Escape") {
|
|
24494
|
+
event.preventDefault();
|
|
24495
|
+
clearFileTreeSearch({ focus: true });
|
|
24496
|
+
}
|
|
24497
|
+
});
|
|
24498
|
+
elements.fileTreeSearchClearButton?.addEventListener("click", () => clearFileTreeSearch({ focus: true }));
|
|
24499
|
+
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
24500
|
+
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
24501
|
+
if (!button) return;
|
|
24502
|
+
const entry = fileContextMenuState?.entry;
|
|
24503
|
+
closeFileContextMenu();
|
|
24504
|
+
if (!entry) return;
|
|
24505
|
+
const action = button.dataset.fileMenuAction || "";
|
|
24506
|
+
if (action === "open-default") openPathInDefaultEditor(entry.path).catch((error) => addEvent(error.message || String(error), "error"));
|
|
24507
|
+
else if (action === "open-webui") openFileTreeEntryInWebui(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
24508
|
+
});
|
|
24509
|
+
elements.fileViewerOpenDefaultButton?.addEventListener("click", () => openPathInDefaultEditor(currentFileViewerPath()));
|
|
24510
|
+
elements.fileViewerResizeHandle?.addEventListener("pointerdown", beginFileViewerResize);
|
|
24511
|
+
elements.fileViewerResizeHandle?.addEventListener("keydown", handleFileViewerResizeKeydown);
|
|
24512
|
+
elements.fileViewerSaveButton?.addEventListener("click", () => saveActiveFileViewer());
|
|
24513
|
+
elements.fileViewerCloseButton?.addEventListener("click", closeFileViewer);
|
|
24514
|
+
elements.fileViewerSourceModeButton?.addEventListener("click", () => setFileViewerMode("source"));
|
|
24515
|
+
elements.fileViewerPreviewModeButton?.addEventListener("click", () => setFileViewerMode("preview"));
|
|
24516
|
+
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
24517
|
+
if (!activeFileViewer) return;
|
|
24518
|
+
activeFileViewer.content = elements.fileViewerEditor.value || "";
|
|
24519
|
+
activeFileViewer.size = new Blob([activeFileViewer.content]).size;
|
|
24520
|
+
setFileViewerDirty(true);
|
|
24521
|
+
updateFileViewerSelectionFromEditor();
|
|
24522
|
+
});
|
|
24523
|
+
for (const eventName of ["select", "keyup", "mouseup"]) {
|
|
24524
|
+
elements.fileViewerEditor?.addEventListener(eventName, updateFileViewerSelectionFromEditor);
|
|
24525
|
+
}
|
|
24526
|
+
elements.fileViewerEditor?.addEventListener("keydown", (event) => {
|
|
24527
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "s") return;
|
|
24528
|
+
event.preventDefault();
|
|
24529
|
+
if (!elements.fileViewerSaveButton?.disabled) saveActiveFileViewer();
|
|
24530
|
+
});
|
|
24531
|
+
for (const eventName of ["keyup", "mouseup"]) {
|
|
24532
|
+
elements.fileViewerPreview?.addEventListener(eventName, () => setTimeout(updateFileViewerSelectionFromPreview, 0));
|
|
24533
|
+
}
|
|
24534
|
+
document.addEventListener("selectionchange", () => {
|
|
24535
|
+
if (activeFileViewer && elements.fileViewerPreview && !elements.fileViewerPreview.hidden) updateFileViewerSelectionFromPreview();
|
|
24536
|
+
});
|
|
24537
|
+
elements.fileSelectionSendButton?.addEventListener("click", () => sendFileSelectionToSession());
|
|
24538
|
+
elements.fileSelectionCommentInput?.addEventListener("keydown", (event) => {
|
|
24539
|
+
if (event.key !== "Enter") return;
|
|
24540
|
+
event.preventDefault();
|
|
24541
|
+
sendFileSelectionToSession();
|
|
24542
|
+
});
|
|
23636
24543
|
elements.pathPickerCreateNameInput.addEventListener("input", updateCreateDirectoryControls);
|
|
23637
24544
|
elements.pathPickerCreateNameInput.addEventListener("keydown", (event) => {
|
|
23638
24545
|
if (event.key !== "Enter") return;
|
|
@@ -23739,6 +24646,7 @@ elements.promptInput.addEventListener("blur", () => {
|
|
|
23739
24646
|
});
|
|
23740
24647
|
|
|
23741
24648
|
resizePromptInput();
|
|
24649
|
+
restoreFileViewerWidthPreference();
|
|
23742
24650
|
focusPromptInput({ defer: true });
|
|
23743
24651
|
restoreStoredSkillUsage();
|
|
23744
24652
|
restoreBusyPromptBehaviorSetting();
|