fix: prevent double insertion from functions list\n\n- Remove flyout-level tap wiring that duplicated item taps\n- Keep a single per-item tap handler for function rows

This commit is contained in:
Codex CLI 2025-09-01 02:59:03 -05:00
commit 2c7670f06c
2 changed files with 4 additions and 30 deletions

View file

@ -136,9 +136,7 @@
<Button.Flyout> <Button.Flyout>
<Flyout <Flyout
IsOpen="{Binding IsFunctionsPanelOpen, Mode=TwoWay}" IsOpen="{Binding IsFunctionsPanelOpen, Mode=TwoWay}"
Placement="BottomEdgeAlignedLeft" Placement="BottomEdgeAlignedLeft">
Opened="OnFunctionsFlyoutOpened"
Closed="OnFunctionsFlyoutClosed">
<Border x:Name="FunctionsPanelRoot" Padding="8" MinWidth="360" MaxHeight="420" <Border x:Name="FunctionsPanelRoot" Padding="8" MinWidth="360" MaxHeight="420"
Background="{DynamicResource Brush.Surface}" BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1" CornerRadius="6"> Background="{DynamicResource Brush.Surface}" BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1" CornerRadius="6">
<ScrollViewer> <ScrollViewer>
@ -162,7 +160,7 @@
<DataTemplate x:DataType="m:FunctionDefinitionItem"> <DataTemplate x:DataType="m:FunctionDefinitionItem">
<Border Background="Transparent" Padding="8" MinHeight="36" <Border Background="Transparent" Padding="8" MinHeight="36"
AutomationProperties.Name="Insert function" AutomationProperties.Name="Insert function"
Tapped="OnFunctionsItemTapped"> Tapped="OnFunctionsItemTapped">
<Grid ColumnDefinitions="*,Auto"> <Grid ColumnDefinitions="*,Auto">
<StackPanel> <StackPanel>
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold"/> <TextBlock Text="{Binding FunctionName}" FontWeight="Bold"/>

View file

@ -21,7 +21,7 @@ public partial class MainView : UserControl
private MainViewModel? _vm; private MainViewModel? _vm;
private ListBox? _historyList; private ListBox? _historyList;
private Border? _functionsPanelRoot; // Functions flyout is handled via per-item Tapped in XAML
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{ {
@ -53,12 +53,6 @@ public partial class MainView : UserControl
_historyList.RemoveHandler(InputElement.TappedEvent, OnHistoryTapped); _historyList.RemoveHandler(InputElement.TappedEvent, OnHistoryTapped);
_historyList = null; _historyList = null;
} }
// Detach functions panel tap handler if still attached
if (_functionsPanelRoot is not null)
{
_functionsPanelRoot.RemoveHandler(InputElement.TappedEvent, OnFunctionsItemTapped);
_functionsPanelRoot = null;
}
_vm = null; _vm = null;
} }
@ -104,23 +98,5 @@ public partial class MainView : UserControl
} }
} }
// Removed Opened/Closed dynamic wiring; handled directly in XAML.
private void OnFunctionsFlyoutOpened(object? sender, EventArgs e)
{
if (sender is Flyout flyout && sender is ContentPresenter presenter)
{
_functionsPanelRoot = presenter.FindControl<Border>("FunctionsPanelRoot");
_functionsPanelRoot?.AddHandler(InputElement.TappedEvent, OnFunctionsItemTapped,
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
}
}
private void OnFunctionsFlyoutClosed(object? sender, EventArgs e)
{
if (_functionsPanelRoot is not null)
{
_functionsPanelRoot.RemoveHandler(InputElement.TappedEvent, OnFunctionsItemTapped);
_functionsPanelRoot = null;
}
}
} }