Skip to content

Commit 714dc5a

Browse files
committed
Fix opening files
Was surprisingly tricky!
1 parent 9f433d8 commit 714dc5a

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

src-tauri/capabilities/default.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
"permissions": [
99
"core:default",
1010
"opener:default",
11+
{
12+
"identifier": "opener:allow-open-path",
13+
"allow": [
14+
{
15+
"path": "**/*"
16+
},
17+
{
18+
"path": "**/.*"
19+
}
20+
]
21+
},
1122
"store:default",
1223
"clipboard-manager:default",
1324
"mcp-bridge:default",

src/lib/file-explorer/BriefList.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
}
125125
126126
// Get entry at global index (handling ".." entry)
127-
function getEntryAt(globalIndex: number): FileEntry | undefined {
127+
export function getEntryAt(globalIndex: number): FileEntry | undefined {
128128
if (hasParent && globalIndex === 0) {
129129
return createParentEntry()
130130
}

src/lib/file-explorer/FilePane.svelte

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,17 @@
331331
// Exported so DualPaneExplorer can forward keyboard events
332332
export function handleKeyDown(e: KeyboardEvent) {
333333
// Handle Enter key - navigate into selected item
334-
if (e.key === 'Enter' && selectedEntry) {
335-
e.preventDefault()
336-
void handleNavigate(selectedEntry)
337-
return
334+
// Use the list component's cached entry instead of selectedEntry to avoid race conditions
335+
// (selectedEntry is fetched asynchronously and may not be ready yet)
336+
if (e.key === 'Enter') {
337+
const listRef = viewMode === 'brief' ? briefListRef : fullListRef
338+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
339+
const entry: FileEntry | undefined = listRef?.getEntryAt(selectedIndex)
340+
if (entry) {
341+
e.preventDefault()
342+
void handleNavigate(entry)
343+
return
344+
}
338345
}
339346
340347
// Handle Backspace or ⌘↑ - go to parent directory
@@ -438,8 +445,14 @@
438445
$effect(() => {
439446
void listen<string>('menu-action', (event) => {
440447
const action = event.payload
441-
if (action === 'open' && selectedEntry) {
442-
void handleNavigate(selectedEntry)
448+
if (action === 'open') {
449+
// Use the list component's cached entry for consistency
450+
const listRef = viewMode === 'brief' ? briefListRef : fullListRef
451+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
452+
const entry: FileEntry | undefined = listRef?.getEntryAt(selectedIndex)
453+
if (entry) {
454+
void handleNavigate(entry)
455+
}
443456
}
444457
})
445458
.then((unsub) => {

src/lib/file-explorer/FullList.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
}
9797
9898
// Get entry at global index (handling ".." entry)
99-
function getEntryAt(globalIndex: number): FileEntry | undefined {
99+
export function getEntryAt(globalIndex: number): FileEntry | undefined {
100100
if (hasParent && globalIndex === 0) {
101101
return createParentEntry()
102102
}

0 commit comments

Comments
 (0)