Skip to content

Commit 02600a6

Browse files
committed
Fixed unexpected visual change when right clicking on text selection
1 parent c3352aa commit 02600a6

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ internal protected virtual void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem
8787

8888
internal protected virtual void OnLayoutUpdated()
8989
{
90-
if (_itemsRepeater is null)
90+
if (_itemsRepeater is null || (_itemsRepeaterLayout.IndexAfterEllipsis > _itemsRepeaterLayout.VisibleItemsCount && _isEllipsisRendered))
9191
return;
9292

93+
if (_ellipsisBreadcrumbBarItem is not null && _isEllipsisRendered != _itemsRepeaterLayout.EllipsisIsRendered)
94+
_ellipsisBreadcrumbBarItem.Visibility = _itemsRepeaterLayout.EllipsisIsRendered ? Visibility.Visible : Visibility.Collapsed;
95+
9396
_isEllipsisRendered = _itemsRepeaterLayout.EllipsisIsRendered;
94-
if (_ellipsisBreadcrumbBarItem is not null)
95-
_ellipsisBreadcrumbBarItem.Visibility = _isEllipsisRendered ? Visibility.Visible : Visibility.Collapsed;
9697

9798
for (int accessibilityIndex = 0, collectionIndex = _itemsRepeaterLayout.IndexAfterEllipsis;
9899
accessibilityIndex < _itemsRepeaterLayout.VisibleItemsCount;

src/Files.App.Controls/Omnibar/Omnibar.Events.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using Windows.System;
5+
46
namespace Files.App.Controls
57
{
68
public partial class Omnibar
79
{
810
private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)
911
{
12+
// Popup width has to be set manually because it doesn't stretch with the parent
1013
_textBoxSuggestionsContainerBorder.Width = ActualWidth;
1114
}
1215

@@ -22,6 +25,10 @@ private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
2225

2326
private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
2427
{
28+
// TextBox still has focus if the context menu for selected text is open
29+
if (_textBox.ContextFlyout.IsOpen)
30+
return;
31+
2532
_isFocused = false;
2633

2734
if (CurrentSelectedMode?.ContentOnInactive is not null)
@@ -33,11 +40,38 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
3340
TryToggleIsSuggestionsPopupOpen(false);
3441
}
3542

43+
private void AutoSuggestBox_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
44+
{
45+
if (e.Key is VirtualKey.Enter)
46+
{
47+
e.Handled = true;
48+
49+
// TODO
50+
}
51+
else if ((e.Key == VirtualKey.Up || e.Key == VirtualKey.Down) && _textBoxSuggestionsPopup.IsOpen)
52+
{
53+
e.Handled = true;
54+
55+
// TODO
56+
}
57+
else if (e.Key == VirtualKey.Escape && _textBoxSuggestionsPopup.IsOpen)
58+
{
59+
e.Handled = true;
60+
61+
// TODO
62+
}
63+
else
64+
{
65+
// TODO
66+
}
67+
}
68+
3669
private void AutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e)
3770
{
38-
if (_shouldPopupOpen)
71+
// After a suggestion item was chosen, text will be changed but we don't want to show suggestions again
72+
if (_suggestionWasClicked)
3973
{
40-
_shouldPopupOpen = false;
74+
_suggestionWasClicked = false;
4175
return;
4276
}
4377

@@ -68,7 +102,7 @@ private void AutoSuggestBoxSuggestionsListView_ItemClick(object sender, ItemClic
68102

69103
TryToggleIsSuggestionsPopupOpen(false);
70104

71-
_shouldPopupOpen = true;
105+
_suggestionWasClicked = true;
72106
}
73107
}
74108
}

src/Files.App.Controls/Omnibar/Omnibar.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using Microsoft.UI.Xaml.Controls;
45
using Microsoft.UI.Xaml.Markup;
56
using Microsoft.UI.Xaml.Media.Animation;
7+
using Windows.Foundation;
68

79
namespace Files.App.Controls
810
{
@@ -27,7 +29,11 @@ public partial class Omnibar : Control
2729
private ListView _textBoxSuggestionsListView = null!;
2830

2931
private bool _isFocused;
30-
private bool _shouldPopupOpen;
32+
private bool _suggestionWasClicked;
33+
34+
// Events
35+
36+
public event TypedEventHandler<Omnibar, OmnibarQuerySubmittedEventArgs>? QuerySubmitted;
3137

3238
// Constructor
3339

@@ -61,6 +67,7 @@ protected override void OnApplyTemplate()
6167
SizeChanged += Omnibar_SizeChanged;
6268
_textBox.GotFocus += AutoSuggestBox_GotFocus;
6369
_textBox.LostFocus += AutoSuggestBox_LostFocus;
70+
_textBox.KeyDown += AutoSuggestBox_KeyDown;
6471
_textBox.TextChanged += AutoSuggestBox_TextChanged;
6572
_textBoxSuggestionsPopup.GettingFocus += AutoSuggestBoxSuggestionsPopup_GettingFocus;
6673
_textBoxSuggestionsListView.ItemClick += AutoSuggestBoxSuggestionsListView_ItemClick;
@@ -168,15 +175,12 @@ public void ChangeMode(OmnibarMode modeToExpand, bool useTransition = true)
168175
}
169176
}
170177

171-
public bool TryToggleIsSuggestionsPopupOpen(bool open)
178+
public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
172179
{
173-
if (open)
174-
{
175-
if (!_isFocused || CurrentSelectedMode?.SuggestionItemsSource is null)
176-
return false;
177-
}
180+
if (wantToOpen && (!_isFocused || CurrentSelectedMode?.SuggestionItemsSource is null))
181+
return false;
178182

179-
_textBoxSuggestionsPopup.IsOpen = open;
183+
_textBoxSuggestionsPopup.IsOpen = wantToOpen;
180184

181185
return false;
182186
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml.Markup;
5+
using Microsoft.UI.Xaml.Media.Animation;
6+
using Windows.Foundation;
7+
8+
namespace Files.App.Controls
9+
{
10+
public record class OmnibarQuerySubmittedEventArgs(OmnibarMode Mode, string Text);
11+
}

tests/Files.App.UITests/Views/BreadcrumbBarPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<controls:SamplePanel Header="Default usage">
1616
<controls:SamplePanel.MainContent>
1717
<Grid
18-
Height="36"
18+
Height="38"
1919
MinWidth="120"
2020
Padding="2"
2121
HorizontalAlignment="Stretch"

0 commit comments

Comments
 (0)