-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: remote PathBar Tab key triggers BrowseRequest when no suggestions #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aeroxy
wants to merge
3
commits into
master
Choose a base branch
from
dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,10 @@ import type { SelectModifiers } from "./components/FileRow"; | |
|
|
||
| export default function App() { | ||
| // Local state | ||
| const [localInfo, setLocalInfo] = useState<{ hostname: string; cwd: string }>({ | ||
| const [localInfo, setLocalInfo] = useState<{ hostname: string; cwd: string; rootDir: string }>({ | ||
| hostname: "...", | ||
| cwd: "...", | ||
| rootDir: "", | ||
| }); | ||
| const [localEntries, setLocalEntries] = useState<FileEntry[]>([]); | ||
| const [localPath, setLocalPath] = useState("."); | ||
|
|
@@ -47,17 +48,23 @@ export default function App() { | |
| // null after refreshes/path-changes so the next click re-establishes the anchor. | ||
| const lastClickedLocalRef = useRef<number | null>(null); | ||
| const lastClickedRemoteRef = useRef<number | null>(null); | ||
| const localRootDirRef = useRef(""); | ||
|
|
||
| const { transfers, startTransfer, updateProgress, completeTransfer, failTransfer, hasActiveTransfers } = useTransfer(); | ||
|
|
||
| // Fetch local file listing via REST | ||
| const fetchLocal = useCallback(async (path: string): Promise<boolean> => { | ||
| setLocalLoading(true); | ||
| try { | ||
| const res = await fetch(`/api/browse?path=${encodeURIComponent(path)}`); | ||
| const root = localRootDirRef.current; | ||
| let relative = path; | ||
| if (root && path.startsWith(root)) { | ||
| relative = path.slice(root.length).replace(/^\//, ""); | ||
| } | ||
| const res = await fetch(`/api/browse?path=${encodeURIComponent(relative)}`); | ||
| if (res.ok) { | ||
| const data: BrowseResponse = await res.json(); | ||
| setLocalInfo({ hostname: data.hostname, cwd: data.cwd }); | ||
| setLocalInfo({ hostname: data.hostname, cwd: data.cwd, rootDir: localRootDirRef.current }); | ||
| setLocalEntries(data.entries); | ||
| setLocalSelected(new Set()); | ||
| lastClickedLocalRef.current = null; | ||
|
|
@@ -78,6 +85,8 @@ export default function App() { | |
| setFingerprint(info.fingerprint ?? null); | ||
| setCanReconnect(info.can_reconnect); | ||
| setLastTarget(info.last_target); | ||
| localRootDirRef.current = info.root_dir; | ||
| setLocalInfo((prev) => ({ ...prev, rootDir: info.root_dir })); | ||
| if (!info.has_remote) { | ||
| setRemoteEntries([]); | ||
| setRemoteInfo({ hostname: "...", cwd: "..." }); | ||
|
|
@@ -306,9 +315,13 @@ export default function App() { | |
|
|
||
| const handleLocalNavigateTo = useCallback( | ||
| async (absolutePath: string) => { | ||
| const success = await fetchLocal(absolutePath); | ||
| const root = localRootDirRef.current; | ||
| const relative = root && absolutePath.startsWith(root) | ||
| ? absolutePath.slice(root.length).replace(/^\//, "") | ||
| : absolutePath; | ||
| const success = await fetchLocal(relative); | ||
| if (success) { | ||
| setLocalPath(absolutePath); | ||
| setLocalPath(relative); | ||
|
Comment on lines
+318
to
+324
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same empty path issue in Consistent with the issue in 🐛 Proposed fix const relative = root && absolutePath.startsWith(root)
- ? absolutePath.slice(root.length).replace(/^\//, "")
+ ? absolutePath.slice(root.length).replace(/^\//, "") || "."
: absolutePath;🤖 Prompt for AI Agents |
||
| } else { | ||
| setError(`Path not found: ${absolutePath}`); | ||
| setTimeout(() => setError(null), 5000); | ||
|
|
@@ -330,8 +343,26 @@ export default function App() { | |
| const lastSlash = inputValue.lastIndexOf("/"); | ||
| const parentDir = lastSlash > 0 ? inputValue.slice(0, lastSlash) : "/"; | ||
| const prefix = inputValue.slice(lastSlash + 1).toLowerCase(); | ||
| const root = localRootDirRef.current; | ||
| // Use cached entries when browsing the current local cwd | ||
| if (parentDir === localInfo.cwd || inputValue === localInfo.cwd) { | ||
| return localEntries | ||
| .filter((e) => e.is_dir && e.name.toLowerCase().startsWith(prefix)) | ||
| .map((e) => `${localInfo.cwd}/${e.name}`); | ||
| } | ||
| let relParent: string; | ||
| if (root && parentDir.startsWith(root)) { | ||
| relParent = parentDir.slice(root.length).replace(/^\//, "") || "."; | ||
| } else if (root && inputValue.startsWith(root)) { | ||
| // inputValue is at or below root_dir, but parentDir is outside — browse root_dir | ||
| relParent = "."; | ||
| } else if (root) { | ||
| return []; // completely outside root_dir — no suggestions | ||
| } else { | ||
| relParent = parentDir; | ||
| } | ||
| try { | ||
| const res = await fetch(`/api/browse?path=${encodeURIComponent(parentDir)}`); | ||
| const res = await fetch(`/api/browse?path=${encodeURIComponent(relParent)}`); | ||
| if (!res.ok) return []; | ||
| const data: BrowseResponse = await res.json(); | ||
| return data.entries | ||
|
|
@@ -340,20 +371,31 @@ export default function App() { | |
| } catch { | ||
| return []; | ||
| } | ||
| }, []); | ||
| }, [localInfo.cwd, localEntries]); | ||
|
|
||
| // Remote suggestions come from the already-fetched remoteEntries for the current directory. | ||
| // Only suggests when the typed parent dir matches the currently viewed remote directory. | ||
| // Remote suggestions — fetch from remote server via REST (no WS side effects) | ||
| const fetchRemoteSuggestions = useCallback(async (inputValue: string): Promise<string[]> => { | ||
| if (!remoteInfo.cwd || remoteInfo.cwd === "...") return []; | ||
| if (!connected || !hasRemote) return []; | ||
| const lastSlash = inputValue.lastIndexOf("/"); | ||
| const parentDir = lastSlash > 0 ? inputValue.slice(0, lastSlash) : "/"; | ||
| const prefix = inputValue.slice(lastSlash + 1).toLowerCase(); | ||
| if (parentDir !== remoteInfo.cwd) return []; | ||
| return remoteEntries | ||
| .filter((e) => e.is_dir && e.name.toLowerCase().startsWith(prefix)) | ||
| .map((e) => `${remoteInfo.cwd}/${e.name}`); | ||
| }, [remoteEntries, remoteInfo.cwd]); | ||
| // Use cached entries when browsing the current remote cwd | ||
| if (parentDir === remoteInfo.cwd || inputValue === remoteInfo.cwd) { | ||
| return remoteEntries | ||
| .filter((e) => e.is_dir && e.name.toLowerCase().startsWith(prefix)) | ||
| .map((e) => `${remoteInfo.cwd}/${e.name}`); | ||
| } | ||
| try { | ||
| const res = await fetch(`/api/browse-remote?path=${encodeURIComponent(parentDir)}`); | ||
| if (!res.ok) return []; | ||
| const data: BrowseResponse = await res.json(); | ||
| return data.entries | ||
| .filter((e) => e.is_dir && e.name.toLowerCase().startsWith(prefix)) | ||
| .map((e) => `${data.cwd}/${e.name}`); | ||
| } catch { | ||
| return []; | ||
| } | ||
| }, [connected, hasRemote, remoteInfo.cwd, remoteEntries]); | ||
|
|
||
| // Transfer actions | ||
| const handleCopyToRemote = useCallback(() => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty path when navigating to exact root directory.
When
path === root,path.slice(root.length)produces an empty string, causing/api/browse?path=to be called. The backend'sserde(default)only applies when the field is absent, not empty—this could fail or behave unexpectedly.Line 355 in
fetchLocalSuggestionscorrectly uses|| "."as a fallback; apply the same here for consistency.🐛 Proposed fix
let relative = path; if (root && path.startsWith(root)) { - relative = path.slice(root.length).replace(/^\//, ""); + relative = path.slice(root.length).replace(/^\//, "") || "."; }📝 Committable suggestion
🤖 Prompt for AI Agents