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
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,40 @@

private bool HasItems => GetCurrentItems().Any();

// The current directory is reflected in the URL as ?path=docs/src so the
// location is deep-linkable (refresh / share / back-forward restore it).
[SupplyParameterFromQuery(Name = "path")]
public string? PathQuery { get; set; }

protected override void OnInitialized()
{
StateService.OnDataChanged += RequestRender;
StateService.OnCurrentPathChanged += RequestRender;
StateService.OnCurrentPathChanged += OnCurrentPathChanged;
StateService.OnSortChanged += RequestRender;
StateService.OnViewModeChanged += RequestRender;
}

// Runs on first render and whenever the query string changes (deep link,
// refresh, browser back/forward): make the current folder match the URL.
protected override void OnParametersSet()
{
var desired = VFSStateService.FromQueryPath(PathQuery);
if (StateService.CurrentPath != desired)
StateService.NavigateTo(desired);
}

// When navigation happens through state (breadcrumb, opening a folder,
// import, etc.) push the matching URL so the address bar stays in sync.
private void OnCurrentPathChanged()
{
var target = VFSStateService.ToFolderUrl(StateService.CurrentPath);
var current = "/" + Navigation.ToBaseRelativePath(Navigation.Uri);
if (!string.Equals(current, target, StringComparison.Ordinal))
Navigation.NavigateTo(target);

InvokeAsync(StateHasChanged);
}

// Service events may fire on non-UI threads; marshal to the Dispatcher.
private void RequestRender() => InvokeAsync(StateHasChanged);

Expand Down Expand Up @@ -483,7 +509,7 @@
public void Dispose()
{
StateService.OnDataChanged -= RequestRender;
StateService.OnCurrentPathChanged -= RequestRender;
StateService.OnCurrentPathChanged -= OnCurrentPathChanged;
StateService.OnSortChanged -= RequestRender;
StateService.OnViewModeChanged -= RequestRender;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@

if (entry.IsDirectory)
{
StateService.NavigateTo(entry.Path);
Navigation.NavigateTo("/");
Navigation.NavigateTo(VFSStateService.ToFolderUrl(entry.Path));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@
{
if (result.IsDirectory)
{
StateService.NavigateTo(result.Path.Value);
RecentFiles.RecordAccess(result.Path.Value, true);
Navigation.NavigateTo("/");
Navigation.NavigateTo(VFSStateService.ToFolderUrl(result.Path.Value));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@

if (item.IsDirectory)
{
StateService.NavigateTo(item.Path);
Navigation.NavigateTo("/");
Navigation.NavigateTo(VFSStateService.ToFolderUrl(item.Path));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@ public string CurrentPath
}
}

/// <summary>The VFS root path scheme.</summary>
public const string RootPath = "vfs://";

/// <summary>
/// Builds the relative app URL that represents a directory, e.g.
/// "vfs://docs/src" -> "/?path=docs/src" (root -> "/"). Segments are
/// individually escaped so the hierarchy stays readable in the address bar.
/// </summary>
public static string ToFolderUrl(string? vfsPath)
{
var relative = StripScheme(vfsPath);
if (string.IsNullOrEmpty(relative))
return "/";

var escaped = string.Join("/", relative.Split('/').Select(Uri.EscapeDataString));
return $"/?path={escaped}";
}

/// <summary>
/// Converts a "path" query value back into a full VFS path, e.g.
/// "docs/src" -> "vfs://docs/src" (null/empty -> "vfs://").
/// </summary>
public static string FromQueryPath(string? queryPath)
{
var relative = (queryPath ?? string.Empty).Replace('\\', '/').Trim('/');
return string.IsNullOrEmpty(relative) ? RootPath : $"{RootPath}{relative}";
}

private static string StripScheme(string? vfsPath)
{
var value = vfsPath ?? string.Empty;
if (value.StartsWith(RootPath, StringComparison.Ordinal))
value = value[RootPath.Length..];
return value.Trim('/');
}

// View preferences
public ViewMode ViewMode
{
Expand Down

Large diffs are not rendered by default.