Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion public/file-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class FileBrowser {
this.currentPath = null;

this.setupDropTarget();
this.setupPathInput();
}

async load(dirPath) {
Expand All @@ -64,7 +65,7 @@ export class FileBrowser {
}

this.currentPath = data.path;
this.pathEl.textContent = data.path;
this.pathEl.value = data.path;
this.pathEl.title = data.path;
this.render(data.items);
} catch (err) {
Expand Down Expand Up @@ -162,6 +163,38 @@ export class FileBrowser {
if (this.onFileInserted) this.onFileInserted(filePath);
}

setupPathInput() {
const input = this.pathEl;

// Focused: left-align and select all, so a paste replaces the whole path.
input.addEventListener('focus', () => {
input.dir = 'ltr';
input.select();
});

// Unfocused: right-align (ellipsis at the start) to show the deepest folder.
input.addEventListener('blur', () => {
input.dir = 'rtl';
if (this.currentPath) input.value = this.currentPath;
});

input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
let path = input.value.trim();
// Strip quotes added by "Copy as path" in Windows Explorer.
if (path.length > 1 && ((path.startsWith('"') && path.endsWith('"')) || (path.startsWith("'") && path.endsWith("'")))) {
path = path.slice(1, -1).trim();
}
if (path && path !== this.currentPath) this.load(path);
input.blur();
} else if (e.key === 'Escape') {
e.preventDefault();
input.blur();
}
});
}

setupDropTarget() {
const input = this.messageInput;

Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</button>
<button class="icon-btn" id="file-sidebar-close" title="Close" aria-label="Close file browser"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>
</div>
<div class="file-sidebar-path" id="file-sidebar-path" title=""></div>
<input class="file-sidebar-path" id="file-sidebar-path" type="text" title="" spellcheck="false" autocomplete="off">
<div class="file-list" id="file-list"></div>
</div>
</div>
Expand Down
16 changes: 15 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,11 @@ body.hide-thinking .thinking-block { display: none !important; }
}

.file-sidebar-path {
padding: 6px 12px;
display: block;
width: calc(100% - 16px);
margin: 0 8px;
box-sizing: border-box;
padding: 6px 4px;
font-size: 10px;
font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
color: var(--text-dim);
Expand All @@ -3028,6 +3032,16 @@ body.hide-thinking .thinking-block { display: none !important; }
text-overflow: ellipsis;
direction: rtl;
text-align: left;
border: none;
background: transparent;
outline: none;
cursor: text;
}

.file-sidebar-path:focus {
color: var(--text-primary);
background: var(--bg-glass-hover);
border-radius: var(--radius-sm);
}

.file-list {
Expand Down