Skip to content

Commit c639e13

Browse files
committed
fix: ChatBox Attchment Overlay bugs
1. overlay sometimes may not disappear 2. overlay will cover the ChatFloatingWindow
1 parent 137fa5a commit c639e13

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/Everywhere/Views/Controls/ChatInputBox.axaml.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using System.Collections.Specialized;
23
using Avalonia.Controls;
34
using Avalonia.Controls.Metadata;
45
using Avalonia.Controls.Primitives;
@@ -210,6 +211,41 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
210211
handledEventsToo: true);
211212
}
212213

214+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
215+
{
216+
base.OnPropertyChanged(change);
217+
218+
if (change.Property == ChatAttachmentItemsSourceProperty)
219+
{
220+
if (change.OldValue is INotifyCollectionChanged oldValue)
221+
{
222+
oldValue.CollectionChanged -= HandleChatAttachmentItemsSourceChanged;
223+
}
224+
if (change.NewValue is INotifyCollectionChanged newValue)
225+
{
226+
newValue.CollectionChanged += HandleChatAttachmentItemsSourceChanged;
227+
}
228+
}
229+
}
230+
231+
private void HandleChatAttachmentItemsSourceChanged(object? sender, NotifyCollectionChangedEventArgs e)
232+
{
233+
if (_visualElementAttachmentOverlayWindow.IsValueCreated)
234+
{
235+
_visualElementAttachmentOverlayWindow.Value.UpdateForVisualElement(null); // Hide the overlay window when the attachment list changes.
236+
}
237+
}
238+
239+
protected override void OnUnloaded(RoutedEventArgs e)
240+
{
241+
base.OnUnloaded(e);
242+
243+
if (_visualElementAttachmentOverlayWindow.IsValueCreated)
244+
{
245+
_visualElementAttachmentOverlayWindow.Value.UpdateForVisualElement(null); // Hide the overlay window when the control is unloaded.
246+
}
247+
}
248+
213249
protected override void OnPointerPressed(PointerPressedEventArgs e)
214250
{
215251
// Because this control is inherited from TextBox, it will receive pointer events and broke the MenuItem's pointer events.

src/Everywhere/Views/Windows/OverlayWindow.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ namespace Everywhere.Views;
44

55
public class OverlayWindow : Window
66
{
7-
// todo: make this window don't cover the owner
7+
private readonly WindowBase? _owner;
8+
89
public OverlayWindow(WindowBase? owner = null)
910
{
10-
Owner = owner;
11+
_owner = owner;
1112

1213
CanResize = false;
1314
ShowInTaskbar = false;
@@ -41,6 +42,12 @@ public void UpdateForVisualElement(IVisualElement? element)
4142
var scaling = DesktopScaling;
4243
Width = boundingRectangle.Width / scaling;
4344
Height = boundingRectangle.Height / scaling;
45+
46+
if (_owner is { Topmost: true })
47+
{
48+
_owner.Topmost = false;
49+
_owner.Topmost = true;
50+
}
4451
}
4552
}
4653
}

0 commit comments

Comments
 (0)