Skip to content

Implement custom text context menus to fix crashes #18854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Blt
blu
BLUESCROLL
bmi
bodgy
BODGY
BOLDFONT
Borland
Expand Down Expand Up @@ -371,8 +372,8 @@ Dcd
DColor
dcommon
DComposition
dde
DDDCCC
dde
DDESHARE
DDevice
DEADCHAR
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalApp/AboutDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TerminalApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
x:Uid="AboutDialog"
DefaultButton="Close"
Expand All @@ -17,6 +18,9 @@

<StackPanel Orientation="Vertical">
<TextBlock IsTextSelectionEnabled="True">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
<Run AutomationProperties.HeadingLevel="1"
Text="{x:Bind ApplicationDisplayName}" /> <LineBreak />
<Run x:Uid="AboutDialog_VersionLabel" />
Expand All @@ -39,7 +43,7 @@
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{x:Bind UpdatesAvailable, Mode=OneWay}">
<TextBlock IsTextSelectionEnabled="False">
<TextBlock>
<Run x:Uid="AboutDialog_UpdateAvailableLabel" />
</TextBlock>
<!-- <Button x:Uid="AboutDialog_InstallUpdateButton"
Expand All @@ -59,4 +63,3 @@
Click="_ThirdPartyNoticesOnClick" />
</StackPanel>
</ContentDialog>

6 changes: 5 additions & 1 deletion src/cascadia/TerminalApp/CommandPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@
IsSpellCheckEnabled="False"
PlaceholderText="{x:Bind SearchBoxPlaceholderText, Mode=OneWay}"
Text=""
TextChanged="_filterTextChanged" />
TextChanged="_filterTextChanged">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>

<TextBlock x:Name="_prefixCharacter"
Grid.Row="0"
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/MarkdownPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace winrt::TerminalApp::implementation
void MarkdownPaneContent::_loadText()
{
auto block = WUX::Controls::TextBlock();
block.ContextFlyout(winrt::Microsoft::Terminal::UI::TextMenuFlyout{});
block.IsTextSelectionEnabled(true);
block.FontFamily(WUX::Media::FontFamily{ L"Cascadia Code" });
block.Text(FileContents());
Expand Down
13 changes: 11 additions & 2 deletions src/cascadia/TerminalApp/MarkdownPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TerminalApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">

Expand Down Expand Up @@ -51,7 +52,11 @@
Grid.Column="0"
Margin="4"
PlaceholderText="Enter a path to a markdown file..."
Text="Z:\dev\simple-test.md" />
Text="Z:\dev\simple-test.md">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>
<StackPanel Grid.Column="1"
Orientation="Horizontal">
<Button Margin="4"
Expand Down Expand Up @@ -105,7 +110,11 @@
FontFamily="Cascadia Code"
IsSpellCheckEnabled="False"
Text="{x:Bind FileContents, Mode=TwoWay}"
Visibility="{x:Bind Editing}" />
Visibility="{x:Bind Editing}">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>

<ScrollViewer x:Name="_scrollViewer"
Grid.Column="1"
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ScratchpadContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace winrt::TerminalApp::implementation
_root.Background(bg.try_as<Media::Brush>());

_box = winrt::Windows::UI::Xaml::Controls::TextBox{};
_box.ContextFlyout(winrt::Microsoft::Terminal::UI::TextMenuFlyout{});
_box.Margin({ 10, 10, 10, 10 });
_box.AcceptsReturn(true);
_box.TextWrapping(TextWrapping::Wrap);
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalApp/SnippetsPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
Grid.Column="1"
Margin="12,0,12,6"
FontFamily="Cascadia Mono, Consolas"
IsTextSelectionEnabled="False"
Style="{ThemeResource BodyTextBlockStyle}"
Text="{x:Bind Input}"
Visibility="{Binding ElementName=rootItem, Path=IsSelected}" />
Expand Down Expand Up @@ -263,7 +262,11 @@
Margin="8,0,8,8"
AllowFocusOnInteraction="True"
TextChanged="_filterTextChanged"
Visibility="{x:Bind HasSnippets, Mode=OneWay}" />
Visibility="{x:Bind HasSnippets, Mode=OneWay}">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>

<mux:TreeView x:Name="_treeView"
Grid.Row="2"
Expand Down
18 changes: 15 additions & 3 deletions src/cascadia/TerminalApp/SuggestionsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@
PlaceholderText="{x:Bind SearchBoxPlaceholderText, Mode=OneWay}"
Text=""
TextChanged="_filterTextChanged"
Visibility="Collapsed" />
Visibility="Collapsed">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>

<StackPanel Grid.Row="1"
Margin="8,0,8,8"
Expand Down Expand Up @@ -224,15 +228,23 @@
FontSize="14"
FontWeight="Bold"
IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords" />
TextWrapping="WrapWholeWords">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
</TextBlock>
<ScrollViewer MaxHeight="64"
VerticalScrollBarVisibility="Visible"
VerticalScrollMode="Enabled"
Visibility="Visible">
<TextBlock x:Name="_descriptionComment"
Margin="0,0,20,0"
IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords" />
TextWrapping="WrapWholeWords">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
</TextBlock>
</ScrollViewer>
</StackPanel>

Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalApp/TabHeaderControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TerminalApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
MinHeight="16"
mc:Ignorable="d">
Expand Down Expand Up @@ -67,6 +68,10 @@
IsSpellCheckEnabled="False"
LostFocus="RenameBoxLostFocusHandler"
MaxLength="1024"
Visibility="Collapsed" />
Visibility="Collapsed">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>
</StackPanel>
</UserControl>
3 changes: 1 addition & 2 deletions src/cascadia/TerminalApp/TabRowControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
FontSize="12">
<ToolTipService.ToolTip>
<ToolTip Placement="Mouse">
<TextBlock IsTextSelectionEnabled="False"
TextWrapping="Wrap">
<TextBlock TextWrapping="Wrap">
<Run x:Uid="NewTabRun" /> <LineBreak />
<Run x:Uid="NewPaneRun"
FontStyle="Italic" /> <LineBreak />
Expand Down
12 changes: 11 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
DefaultButton="Primary">
<TextBlock IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
<Run x:Name="NoticeMessage" />
</TextBlock>
</ContentDialog>
Expand All @@ -148,6 +151,9 @@
DefaultButton="Primary">
<TextBlock IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
<Run x:Name="CouldNotOpenUriReason" /> <LineBreak />
<Run x:Name="UnopenedUri"
FontFamily="Cascadia Mono" />
Expand Down Expand Up @@ -191,7 +197,11 @@
<TextBox x:Name="WindowRenamerTextBox"
KeyDown="_WindowRenamerKeyDown"
KeyUp="_WindowRenamerKeyUp"
Text="{x:Bind WindowProperties.WindowName, Mode=OneWay}" />
Text="{x:Bind WindowProperties.WindowName, Mode=OneWay}">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>
</mux:TeachingTip.Content>
</mux:TeachingTip>

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ namespace winrt::TerminalApp::implementation
auto buttonText = RS_(L"Ok");

Controls::TextBlock warningsTextBlock;
warningsTextBlock.ContextFlyout(winrt::Microsoft::Terminal::UI::TextMenuFlyout{});
// Make sure you can copy-paste
warningsTextBlock.IsTextSelectionEnabled(true);
// Make sure the lines of text wrap
Expand Down Expand Up @@ -482,6 +483,7 @@ namespace winrt::TerminalApp::implementation
auto buttonText = RS_(L"Ok");

Controls::TextBlock warningsTextBlock;
warningsTextBlock.ContextFlyout(winrt::Microsoft::Terminal::UI::TextMenuFlyout{});
// Make sure you can copy-paste
warningsTextBlock.IsTextSelectionEnabled(true);
// Make sure the lines of text wrap
Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalControl/SearchBoxControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Terminal.Control"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
x:Name="Root"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Expand Down Expand Up @@ -197,7 +198,11 @@
VerticalAlignment="Center"
IsSpellCheckEnabled="False"
KeyDown="TextBoxKeyDown"
TextChanged="TextBoxTextChanged" />
TextChanged="TextBoxTextChanged">
<TextBox.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBox.ContextFlyout>
</TextBox>

<TextBlock x:Name="StatusBox"
x:Uid="SearchBox_StatusBox"
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/TermControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Terminal.Control"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Expand Down Expand Up @@ -1272,6 +1273,9 @@
Placement="Mouse">
<TextBlock IsTextSelectionEnabled="True"
TextWrapping="Wrap">
<TextBlock.ContextFlyout>
<mtu:TextMenuFlyout />
</TextBlock.ContextFlyout>
<Run x:Name="HoveredUri" /> <LineBreak />
<Run x:Uid="HowToOpenRun"
FontStyle="Italic" />
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsEditor/CommonResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<Style x:Key="TextBoxSettingStyle"
BasedOn="{StaticResource DefaultTextBoxStyle}"
TargetType="TextBox">
<Setter Property="ContextFlyout">
<Setter.Value>
<mtu:TextMenuFlyout />
</Setter.Value>
</Setter>
Comment on lines +135 to +139
Copy link
Member Author

@lhecker lhecker Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this app-wide? This here fixes almost all occurrences of selectable text, thankfully.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the only thing I can think of is doing it similar to above, but without an x:Key value, so it would apply it to all the textboxes. Like this:

<!--- BODGY: <reason> --->
<Style BasedOn="{StaticResource DefaultTextBoxStyle}"
       TargetType="TextBox">
   <Setter Property="ContextFlyout">
      <Setter.Value>
         <mtu:TextMenuFlyout />
      </Setter.Value>
   </Setter>
</Style>

At the bug bash today, I think Dustin also suggested trying to add it at the App.xaml layer or something like that (probably the XAML file you import WinUI 2).

<Setter Property="MinWidth" Value="{StaticResource StandardBoxMinWidth}" />
<Setter Property="MaxWidth" Value="400" />
<Setter Property="HorizontalAlignment" Value="Left" />
Expand Down
Loading
Loading