Compare commits
No commits in common. "b8ba57a7073e841ecf532719d47628c272a519ac" and "5a5892edb752dd06b72db2d97a036260a95ccfb9" have entirely different histories.
b8ba57a707
...
5a5892edb7
3 changed files with 31 additions and 19 deletions
|
@ -35,10 +35,6 @@ public partial class MainViewModel : ViewModelBase
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private int _selectedHistoryIndex = -1;
|
private int _selectedHistoryIndex = -1;
|
||||||
|
|
||||||
// Caret position in the input TextBox
|
|
||||||
[ObservableProperty]
|
|
||||||
private int _caretIndex;
|
|
||||||
|
|
||||||
public ObservableCollection<HistoryItem> History { get; }
|
public ObservableCollection<HistoryItem> History { get; }
|
||||||
public ObservableCollection<VariableItem> Variables { get; }
|
public ObservableCollection<VariableItem> Variables { get; }
|
||||||
|
|
||||||
|
@ -65,11 +61,6 @@ public partial class MainViewModel : ViewModelBase
|
||||||
if (string.IsNullOrWhiteSpace(functionDefintionItem.FunctionName))
|
if (string.IsNullOrWhiteSpace(functionDefintionItem.FunctionName))
|
||||||
return;
|
return;
|
||||||
InsertToken(functionDefintionItem.FunctionName + "()");
|
InsertToken(functionDefintionItem.FunctionName + "()");
|
||||||
// Place caret inside the parentheses
|
|
||||||
if (!string.IsNullOrEmpty(InputText))
|
|
||||||
{
|
|
||||||
CaretIndex = Math.Max(0, InputText.Length - 1);
|
|
||||||
}
|
|
||||||
// Close the functions flyout after insertion for smoother UX
|
// Close the functions flyout after insertion for smoother UX
|
||||||
IsFunctionsPanelOpen = false;
|
IsFunctionsPanelOpen = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,9 @@
|
||||||
<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>
|
||||||
|
@ -183,9 +185,7 @@
|
||||||
<TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static m:IconFont.Function}" />
|
<TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static m:IconFont.Function}" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<TextBox x:Name="InputBox" Grid.Column="2" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
<TextBox Grid.Column="2" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinHeight="44"
|
||||||
CaretIndex="{Binding CaretIndex, Mode=TwoWay}"
|
|
||||||
MinHeight="44"
|
|
||||||
AutomationProperties.Name="Expression input"
|
AutomationProperties.Name="Expression input"
|
||||||
Watermark="Type an expression (e.g., 2 + 2)">
|
Watermark="Type an expression (e.g., 2 + 2)">
|
||||||
<InputElement.KeyBindings>
|
<InputElement.KeyBindings>
|
||||||
|
|
|
@ -21,7 +21,7 @@ public partial class MainView : UserControl
|
||||||
|
|
||||||
private MainViewModel? _vm;
|
private MainViewModel? _vm;
|
||||||
private ListBox? _historyList;
|
private ListBox? _historyList;
|
||||||
// Functions flyout is handled via per-item Tapped in XAML
|
private Border? _functionsPanelRoot;
|
||||||
|
|
||||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +53,12 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,12 +100,27 @@ public partial class MainView : UserControl
|
||||||
_vm?.InsertFunctionCommand.CanExecute(item) == true)
|
_vm?.InsertFunctionCommand.CanExecute(item) == true)
|
||||||
{
|
{
|
||||||
_vm.InsertFunctionCommand.Execute(item);
|
_vm.InsertFunctionCommand.Execute(item);
|
||||||
// Return focus to the input box so the caret is active
|
|
||||||
var input = this.FindControl<TextBox>("InputBox");
|
|
||||||
input?.Focus();
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue