Fixed insertion bug

This commit is contained in:
Jordan Wages 2025-08-27 23:30:22 -05:00
commit b9de2cae2d

View file

@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using AdvancedCalculator.Models;
using AdvancedCalculator.Services;
using CSMic;
namespace AdvancedCalculator.ViewModels;
@ -43,19 +44,21 @@ public partial class MainViewModel : ViewModelBase
// Insert helpers for touch: appends tokens to the input box
[RelayCommand]
private void InsertVariable(string? variableName)
private void InsertVariable(VariableItem variableItem)
{
if (string.IsNullOrWhiteSpace(variableName))
if(variableItem == null) return;
if (string.IsNullOrWhiteSpace(variableItem.VariableName))
return;
InsertToken(variableName);
InsertToken(variableItem.VariableName);
}
[RelayCommand]
private void InsertFunction(string? functionName)
private void InsertFunction(FunctionDefinitionItem functionDefintionItem)
{
if (string.IsNullOrWhiteSpace(functionName))
if(functionDefintionItem == null) return;
if (string.IsNullOrWhiteSpace(functionDefintionItem.FunctionName))
return;
InsertToken(functionName + "()");
InsertToken(functionDefintionItem.FunctionName + "()");
// Close the functions flyout after insertion for smoother UX
IsFunctionsPanelOpen = false;
}