diff --git a/Directory.Packages.props b/Directory.Packages.props index 97ffb8a..85bb50d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -51,7 +51,7 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/VelaShell.Plugin.Mongo/Ui/Shell/MongoWorkspaceView.axaml.cs b/plugins/VelaShell.Plugin.Mongo/Ui/Shell/MongoWorkspaceView.axaml.cs index 1970788..3872d89 100644 --- a/plugins/VelaShell.Plugin.Mongo/Ui/Shell/MongoWorkspaceView.axaml.cs +++ b/plugins/VelaShell.Plugin.Mongo/Ui/Shell/MongoWorkspaceView.axaml.cs @@ -18,10 +18,9 @@ public sealed partial class MongoWorkspaceView : UserControl, IViewServices /// 用给定的视图模型初始化。 /// 视图模型。 - internal MongoWorkspaceView(MongoWorkspaceViewModel viewModel) + internal MongoWorkspaceView(MongoWorkspaceViewModel viewModel) : this() { _viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel)); - InitializeComponent(); DataContext = viewModel; viewModel.ViewServices = this; AddHandler(KeyDownEvent, OnKeyDown, RoutingStrategies.Tunnel); @@ -34,6 +33,7 @@ public MongoWorkspaceView() { _viewModel = null!; InitializeComponent(); + _ = new DialogMovement(DialogArea, DialogFrame, DialogGrip, DialogResizeGrip); } private void OnTreeDoubleTapped(object? sender, TappedEventArgs e) diff --git a/tests/VelaShell.Plugin.Mongo.Tests/BindingHygieneTests.cs b/tests/VelaShell.Plugin.Mongo.Tests/BindingHygieneTests.cs index 4c85839..94483a3 100644 --- a/tests/VelaShell.Plugin.Mongo.Tests/BindingHygieneTests.cs +++ b/tests/VelaShell.Plugin.Mongo.Tests/BindingHygieneTests.cs @@ -1,4 +1,6 @@ using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; using Avalonia.Logging; using Avalonia.VisualTree; using VelaShell.Plugin.Mongo.Ui; @@ -45,6 +47,45 @@ private static async Task WaitAsync(Func condition, int timeoutMs = 15_000 } } + [TestMethod] + public void Editor_loads_completion_content_only_for_matches_and_reuses_it() => Screens.OnUi(static async () => + { + var editor = new CodeEditor(); + var window = new Window { Width = 600, Height = 400, Content = editor }; + var theme = new Uri("avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml"); + window.Styles.Add(new Avalonia.Markup.Xaml.Styling.StyleInclude(theme) { Source = theme }); + try + { + window.Show(); + editor.FocusEditor(); + await Screens.PumpAsync(3); + Popup popup = editor.GetVisualDescendants().OfType().Single(); + popup.ShouldUseOverlayLayer = true; + editor.CompletionProvider = _ => Task.FromResult(null); + editor.RequestCompletion(); + Assert.IsNull(popup.Child); + + editor.CompletionProvider = _ => Task.FromResult(new() + { + ReplaceOffset = 0, ReplaceLength = 0, Items = [new() { Label = "find" }] + }); + editor.RequestCompletion(); + Assert.IsTrue(popup.IsOpen); + Control? first = popup.Child; + Assert.IsNotNull(first); + editor.Editor.TextArea.RaiseEvent(new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = Key.Escape }); + Assert.IsFalse(popup.IsOpen); + editor.RequestCompletion(); + Assert.AreSame(first, popup.Child); + editor.Editor.TextArea.RaiseEvent(new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = Key.Tab }); + Assert.AreEqual("find", editor.Text); + } + finally + { + window.Close(); + } + }); + [TestMethod] public void Walking_the_main_screens_raises_no_binding_errors() => Screens.OnUi(async () => { diff --git a/tests/VelaShell.Plugin.Mongo.Tests/ConnectionManagementTests.cs b/tests/VelaShell.Plugin.Mongo.Tests/ConnectionManagementTests.cs index 7274baf..ff728c5 100644 --- a/tests/VelaShell.Plugin.Mongo.Tests/ConnectionManagementTests.cs +++ b/tests/VelaShell.Plugin.Mongo.Tests/ConnectionManagementTests.cs @@ -1,4 +1,7 @@ +using Avalonia; using Avalonia.Controls; +using Avalonia.Headless; +using Avalonia.Input; using Avalonia.VisualTree; using MongoDB.Driver; using VelaShell.Plugin.Mongo.Core; @@ -74,6 +77,53 @@ public void Empty_workbench_offers_a_new_connection() => Screens.OnUi(static asy } }); + [TestMethod] + public void Dragging_dialog_and_nested_confirmation_keeps_separate_positions() => Screens.OnUi(static async () => + { + using var context = new TestPluginContext(); + (MongoWorkspaceViewModel shell, MongoWorkspaceView view, Window window) = await OpenEmptyAsync(context); + try + { + shell.NewConnectionCommand.Execute(null); + await Screens.PumpAsync(3); + Border frame = view.FindControl("DialogFrame")!; + Control grip = view.FindControl("DialogGrip")!; + Point Origin() => frame.TranslatePoint(default, window)!.Value; + void Drag(Vector by) + { + Point start = grip.TranslatePoint(new Point(20, 12), window)!.Value; + window.MouseDown(start, MouseButton.Left); + window.MouseMove(start + by, RawInputModifiers.LeftMouseButton); + window.MouseUp(start + by, MouseButton.Left); + } + Point origin = Origin(); + using var frameImage = Screens.Capture(window, "connection-dialog-chrome"); + Assert.IsNotNull(frameImage); + Drag(new(50, 15)); + Point moved = Origin(); + Assert.AreEqual(origin + new Vector(50, 15), moved); + + Task result = shell.ConfirmAsync(new() { Title = "Confirm", Message = "Continue?", ConfirmLabel = "OK" }); + await Screens.PumpAsync(3); + Point centered = Origin(); + Assert.AreEqual((window.Bounds.Width - frame.Bounds.Width) / 2, centered.X, 1); + Drag(new(-2000, -2000)); + Assert.AreEqual(new Point(0, 0), Origin()); + Button close = frame.GetVisualDescendants().OfType