From 8d8795fcb6ff3457a69b016c82fba8211cf99190 Mon Sep 17 00:00:00 2001 From: Nitesh Date: Mon, 30 Nov 2026 19:50:46 +0545 Subject: [PATCH 1/3] feat(location): open a typed file path's folder with the file selected --- docs/user/navigation.md | 2 + src/app/page/location_bar_controller.cpp | 4 +- src/browser/browser_controller.cpp | 51 ++++++++++++++++++++++-- src/browser/browser_controller.h | 5 +++ tests/browser_controller_test.cpp | 34 ++++++++++++++++ 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/docs/user/navigation.md b/docs/user/navigation.md index a9308dcb..b623fc65 100644 --- a/docs/user/navigation.md +++ b/docs/user/navigation.md @@ -6,6 +6,8 @@ Move between folders with the location bar, history, search and the keyboard. By default, the location bar shows clickable folder breadcrumbs. Double-click a breadcrumb or unused space, or press `Ctrl+L`, to edit the path. While you type a folder name, the rest of the first matching folder is filled in and selected: keep typing to narrow it, `Backspace` removes it, and `Tab`, `Right`, `End` or `Enter` accept it. `Escape` removes the suggestion; press it again to stop editing. `Tab` accepts a path completion when one is available. +Enter or paste the path of a file to open its folder with that file selected. This also works in the file picker. + Home and its descendants use Home as the breadcrumb root. You can still navigate above it. Suggestions stay asynchronous while you type a network address. An unavailable or unmounted parent does not prevent you from finishing and submitting the address. Suggestions from remote folders keep their URI form, including escaped spaces and other filename bytes. diff --git a/src/app/page/location_bar_controller.cpp b/src/app/page/location_bar_controller.cpp index 450f3f8b..1248bac1 100644 --- a/src/app/page/location_bar_controller.cpp +++ b/src/app/page/location_bar_controller.cpp @@ -80,7 +80,9 @@ std::unique_ptr LocationBarController::buildLocationArea() { .onChange = [this](const std::string& text) { requestCompletions(text); }, .onSubmit = [this](const std::string& text) { - m_locationInvalid = !m_page.browser().openText(text); + m_locationInvalid = !m_page.browser().openTypedText(text, [this](const luciole::Location& file) { + m_page.revealOnReload({file}); + }); if (!m_locationInvalid) { endLocationEdit(true); } diff --git a/src/browser/browser_controller.cpp b/src/browser/browser_controller.cpp index 1761fd58..2ea3d2d8 100644 --- a/src/browser/browser_controller.cpp +++ b/src/browser/browser_controller.cpp @@ -94,6 +94,7 @@ luciole::BrowserController::~BrowserController() { m_lifetime.reset(); m_mount.reset(); m_duplicateToken.cancel(); + m_typedTextToken.cancel(); cancelSearchTimeout(); m_activation->resolved = {}; m_activation->token.cancel(); @@ -115,6 +116,7 @@ void luciole::BrowserController::advanceContext() { m_restoreBulkMetadata = false; cancelSearchTimeout(); m_contextSerial = ++nextContext; + m_typedTextToken.cancel(); m_activation->token.cancel(); m_activation->token = CancelToken{}; } @@ -254,20 +256,61 @@ void luciole::BrowserController::open(const Location& location) { loadVisit(); } -bool luciole::BrowserController::openText(const std::string& text) { +std::optional luciole::BrowserController::resolveText(const std::string& text) { if (text.empty()) { showMessage(i18n::tr("browser.browser-controller.enter-path-or-uri")); - return false; + return std::nullopt; } try { const auto base = m_model.snapshot().location ? *m_model.snapshot().location : Location::fromPath(std::filesystem::current_path().native()); - open(resolveLocationText(text, base)); - return true; + return resolveLocationText(text, base); } catch (const std::exception& error) { showMessage(error.what()); + return std::nullopt; + } +} + +bool luciole::BrowserController::openText(const std::string& text) { + const auto location = resolveText(text); + if (!location) { + return false; + } + open(*location); + return true; +} + +bool luciole::BrowserController::openTypedText( + const std::string& text, std::function revealFile +) { + const auto location = resolveText(text); + if (!location) { return false; } + m_typedTextToken.cancel(); + m_typedTextToken = CancelToken{}; + const auto token = m_typedTextToken; + const std::weak_ptr lifetime = m_lifetime; + // Anything but a file, including a missing path, opens as before so the folder load reports it. + queryFileType( + *location, token, + [this, lifetime, token, target = *location, + revealFile = std::move(revealFile)](std::expected type) { + if (lifetime.expired() || token.cancelled()) { + return; + } + const auto parent = target.parent(); + if (!type || (*type != FileType::Regular && *type != FileType::Special) || !parent) { + open(target); + return; + } + open(*parent); + if (revealFile) { + revealFile(target); + } + } + ); + return true; } void luciole::BrowserController::home() { (void)openText("~"); } diff --git a/src/browser/browser_controller.h b/src/browser/browser_controller.h index 489d0e2d..63cee0aa 100644 --- a/src/browser/browser_controller.h +++ b/src/browser/browser_controller.h @@ -42,6 +42,9 @@ namespace luciole { // Keeps the current folder while a device unlocks. Navigation cancels the pending request. void openDrive(DriveMonitor& drives, const std::string& key, std::function done); bool openText(const std::string& text); + // Like openText, but a path to a file opens its folder and then passes the file to `revealFile`. The type check + // runs in the background; a newer typed location or any navigation before it finishes drops it. + bool openTypedText(const std::string& text, std::function revealFile); void setCaptureViewport(std::function callback); void setViewDefaults(ViewMode mode, int iconSize); // The view mode of folders without their own; the current folder keeps its own mode if it has one. @@ -135,6 +138,7 @@ namespace luciole { void notify() const; void publish(DirectorySnapshot snapshot); void showMessage(std::string message); + std::optional resolveText(const std::string& text); void cancelSearchTimeout(); void scheduleSearch(); void startSearch(); @@ -160,6 +164,7 @@ namespace luciole { bool m_updatingMetadata = false; bool m_restoreBulkMetadata = false; CancelToken m_duplicateToken; + CancelToken m_typedTextToken; bool m_duplicateFactsPending = false; struct PendingMetadata { std::uint64_t context; diff --git a/tests/browser_controller_test.cpp b/tests/browser_controller_test.cpp index 7540eddb..1041339a 100644 --- a/tests/browser_controller_test.cpp +++ b/tests/browser_controller_test.cpp @@ -362,6 +362,39 @@ namespace { browser.refresh(); pump.ready(browser); } + void testTypedFilePaths() { + Fixture fixture; + Pump pump; + BrowserController browser({}, false); + const auto root = Location::fromPath(fixture.path.native()); + const auto child = Location::fromPath((fixture.path / "child").native()); + browser.open(root); + pump.ready(browser); + std::vector revealed; + const auto reveal = [&](const Location& file) { revealed.push_back(file); }; + TEST_CHECK(browser.openTypedText((fixture.path / "child" / "inside").native(), reveal)); + pump.until([&] { return !revealed.empty(); }); + pump.ready(browser); + TEST_CHECK(browser.model().snapshot().location == child); + TEST_CHECK(revealed == std::vector{Location::fromPath((fixture.path / "child" / "inside").native())}); + TEST_CHECK(browser.canBack()); + revealed.clear(); + TEST_CHECK(browser.openTypedText("../folder-link", reveal)); + pump.until([&] { + return browser.model().snapshot().location == Location::fromPath((fixture.path / "folder-link").native()); + }); + pump.ready(browser); + TEST_CHECK(revealed.empty()); + TEST_CHECK(browser.openTypedText((fixture.path / "missing").native(), reveal)); + pump.until([&] { return browser.model().snapshot().status == DirectoryStatus::Error; }); + TEST_CHECK(revealed.empty()); + TEST_CHECK(!browser.openTypedText("sftp://invalid%zz", reveal) && !browser.message().empty()); + TEST_CHECK(browser.openTypedText((fixture.path / "file").native(), reveal)); + browser.open(child); + pump.ready(browser); + pump.drainFor(30ms); + TEST_CHECK(revealed.empty() && browser.model().snapshot().location == child); + } void testRecursiveSearch() { Fixture fixture; Fixture outside; @@ -1077,6 +1110,7 @@ int main() { testDuplicatedTabs(); testNavigation(); testFailureAndLiveUpdates(); + testTypedFilePaths(); testRecursiveSearch(); testBackupPolicyAndSearch(); testSearchLifetimeAndPartialFailure(); From 0feed6e1b8df4d8e193920c65edc357072fe5498 Mon Sep 17 00:00:00 2001 From: Lemmy <2170677+ItsLemmy@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:26:45 -0500 Subject: [PATCH 2/3] refactor(browser): drop the unused null check on the typed path reveal callback --- src/browser/browser_controller.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/browser/browser_controller.cpp b/src/browser/browser_controller.cpp index 2ea3d2d8..9925d79a 100644 --- a/src/browser/browser_controller.cpp +++ b/src/browser/browser_controller.cpp @@ -305,9 +305,7 @@ bool luciole::BrowserController::openTypedText( return; } open(*parent); - if (revealFile) { - revealFile(target); - } + revealFile(target); } ); return true; From ac900fe03771792772fe85bdad91a8c45b3a299f Mon Sep 17 00:00:00 2001 From: Lemmy <2170677+ItsLemmy@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:26:45 -0500 Subject: [PATCH 3/3] docs(navigation): say that a typed file path opens on Enter --- docs/user/navigation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/navigation.md b/docs/user/navigation.md index b623fc65..f74ef23a 100644 --- a/docs/user/navigation.md +++ b/docs/user/navigation.md @@ -6,7 +6,7 @@ Move between folders with the location bar, history, search and the keyboard. By default, the location bar shows clickable folder breadcrumbs. Double-click a breadcrumb or unused space, or press `Ctrl+L`, to edit the path. While you type a folder name, the rest of the first matching folder is filled in and selected: keep typing to narrow it, `Backspace` removes it, and `Tab`, `Right`, `End` or `Enter` accept it. `Escape` removes the suggestion; press it again to stop editing. `Tab` accepts a path completion when one is available. -Enter or paste the path of a file to open its folder with that file selected. This also works in the file picker. +Type or paste the path of a file and press `Enter` to open its folder with that file selected. This also works in the file picker. Home and its descendants use Home as the breadcrumb root. You can still navigate above it.