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
1 change: 1 addition & 0 deletions App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
EmbeddedAssets.WarmUp();
desktop.MainWindow = services.GetRequiredService<MainWindowFactory>().Create();
SystemMonospaceFonts.WarmUp();
}
Expand Down
10 changes: 10 additions & 0 deletions Services/DocumentFileIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Inlay;

internal static class DocumentFileIdentity
{
public static StringComparer Comparer { get; } =
OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;

public static bool Matches(IDocumentFile? file, string identity) =>
file is not null && Comparer.Equals(file.Identity, identity);
}
16 changes: 16 additions & 0 deletions Services/EmbeddedAssets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia.Platform;

namespace Inlay;

internal static class EmbeddedAssets
{
public static Uri Uri(string name) => new($"avares://Inlay/Assets/{name}");

// The toolbar's Svg controls each load on their own thread as the first window
// is built. Reading one asset here builds this assembly's resource table once,
// on the UI thread, before those loads start racing for it.
public static void WarmUp()
{
using var stream = AssetLoader.Open(Uri("new-document.svg"));
}
}
13 changes: 13 additions & 0 deletions Services/TabDragDrop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Avalonia.Input;
using Inlay.ViewModels;

namespace Inlay;

internal sealed class TabDragPayload
{
public static readonly DataFormat<TabDragPayload> Format =
DataFormat.CreateInProcessFormat<TabDragPayload>("application/x-inlay-tab");

public required MainWindow SourceWindow { get; init; }
public required DocumentTabViewModel SourceTab { get; init; }
}
22 changes: 22 additions & 0 deletions Tests/Behavior/Application/ApplicationBehaviorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,32 @@ public void NewWindowsHaveIndependentDocumentState()
}
}

[AvaloniaFact]
public void ClosingAWindowReleasesItsTabsWithoutDisturbingTheBoundSelection()
{
var (window, viewModel) = MainWindowTestHost.CreateWindow();
var tab = viewModel.SelectedDocument!;
var editor = MainWindowTestHost.FindEditor(window);

window.Close();

// The window is still bound to Documents while it closes, so emptying the
// collection here would push a null selection back through SelectedDocument
// and every SelectedDocument.* binding would fail.
Assert.Same(tab, viewModel.SelectedDocument);
Assert.Single(viewModel.Documents);

// The tab is disposed all the same, so its editor no longer feeds it changes.
editor.Text = "Edited after the window closed";
Assert.False(tab.IsDirty);
}

private static MainWindow CreateWindow(FakeInteractionService interaction) =>
#pragma warning disable CA2000 // Ownership passes to the caller.
new(new MainWindowViewModel(
new JsonTemplateDocumentService(),
new FakeStorageService(),
interaction,
new FakeApplicationService()));
#pragma warning restore CA2000
}
2 changes: 1 addition & 1 deletion Tests/Behavior/MainWindow/LineLengthBehaviorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void FlyoutControlsUpdateTheSelectedDocumentAndEditor()
[AvaloniaFact]
public async Task OpeningADocumentAppliesItsLineSettingsWithoutMarkingItDirty()
{
var context = MainWindowViewModelTestContext.Create();
using var context = MainWindowViewModelTestContext.Create();
var file = new MemoryDocumentFile("configured.itd");
file.SetRawContents("""
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Behavior/MainWindow/MainWindowCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void ViewCommandsUpdateRenderedState()
[AvaloniaFact]
public async Task FontCommandUpdatesTheRenderedEditorFamily()
{
var context = MainWindowViewModelTestContext.Create();
using var context = MainWindowViewModelTestContext.Create();
var initialFont = context.ViewModel.EditorFontFamily;
context.Interaction.SelectedFont = new FontFamily("DejaVu Sans Mono");
var window = new MainWindow(context.ViewModel);
Expand Down
Loading