feat: place caret inside inserted function parentheses\n\n- Add CaretIndex to MainViewModel and bind TextBox.CaretIndex\n- After function insertion, set caret to inside parentheses\n- Return focus to input box for immediate typing
This commit is contained in:
parent
2c7670f06c
commit
b8ba57a707
3 changed files with 15 additions and 1 deletions
|
@ -35,6 +35,10 @@ 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; }
|
||||||
|
|
||||||
|
@ -61,6 +65,11 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,9 @@
|
||||||
<TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static m:IconFont.Function}" />
|
<TextBlock FontFamily="{StaticResource MDI}" Text="{x:Static m:IconFont.Function}" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<TextBox Grid.Column="2" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinHeight="44"
|
<TextBox x:Name="InputBox" Grid.Column="2" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||||
|
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>
|
||||||
|
|
|
@ -94,6 +94,9 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue