Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/user/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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.

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.
Expand Down
4 changes: 3 additions & 1 deletion src/app/page/location_bar_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ std::unique_ptr<Flex> 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);
}
Expand Down
49 changes: 45 additions & 4 deletions src/browser/browser_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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{};
}
Expand Down Expand Up @@ -254,20 +256,59 @@ void luciole::BrowserController::open(const Location& location) {
loadVisit();
}

bool luciole::BrowserController::openText(const std::string& text) {
std::optional<luciole::Location> 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<void(const Location&)> 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<int> 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<FileType, FileError> 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);
revealFile(target);
}
);
return true;
}

void luciole::BrowserController::home() { (void)openText("~"); }
Expand Down
5 changes: 5 additions & 0 deletions src/browser/browser_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(std::string)> 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<void(const Location&)> revealFile);
void setCaptureViewport(std::function<BrowseViewport()> 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.
Expand Down Expand Up @@ -135,6 +138,7 @@ namespace luciole {
void notify() const;
void publish(DirectorySnapshot snapshot);
void showMessage(std::string message);
std::optional<Location> resolveText(const std::string& text);
void cancelSearchTimeout();
void scheduleSearch();
void startSearch();
Expand All @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions tests/browser_controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location> 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;
Expand Down Expand Up @@ -1077,6 +1110,7 @@ int main() {
testDuplicatedTabs();
testNavigation();
testFailureAndLiveUpdates();
testTypedFilePaths();
testRecursiveSearch();
testBackupPolicyAndSearch();
testSearchLifetimeAndPartialFailure();
Expand Down
Loading