public void Do () { Region.SetNeedToEvaluate (true); var name = Enum.GetName (typeof(Key), Key).ToLower (); var character = name.Length > 1 ? name [1] : name [0]; if (Region.Selection.SelectedToken is TextToken == false) { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); } var textToken = Region.Selection.SelectedToken as TextToken; if (!string.IsNullOrEmpty (textToken.Text) && Regex.IsMatch (textToken.Text, @"^\d") && Regex.IsMatch (character.ToString (), @"\D")) { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); } textToken = Region.Selection.SelectedToken as TextToken; if (string.IsNullOrEmpty (textToken.Text)) textToken.Text += character; else textToken.Text = textToken.Text.Insert (Region.Selection.Position, character.ToString ()); Region.Selection.Position++; }
public void Do () { var selectedToken = Region.Selection.SelectedToken; if (selectedToken.Parent == null || selectedToken.Parent is HBoxToken == false || selectedToken.Parent.Parent is ParenthesesToken == false) return; var parentheses = selectedToken.Parent.Parent as ParenthesesToken; if (parentheses.ShowCloseParentheses) return; Region.SetNeedToEvaluate (true); if (Region.Selection.SelectedToken is TextToken == false) { if (Region.Selection.Type == SelectionType.Left) { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); } } else { var textToken = Region.Selection.SelectedToken as TextToken; if (!string.IsNullOrEmpty (textToken.Text) && Regex.IsMatch (textToken.Text, @"\d+") && Region.Selection.Position != textToken.Text.Length) { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); new LeftAction (Region).Do (); } } var parent = GetHBoxToken (Region.Selection.SelectedToken); var index = parent.Tokens.IndexOf (Region.Selection.SelectedToken); var container = GetHBoxToken (parentheses); var i = container.Tokens.IndexOf (parent.Parent) + 1; foreach (var token in parent.Tokens.Skip (index + 1).ToList()) { parent.Tokens.Remove (token); container.Tokens.Insert (i, token); i++; } parentheses.ShowCloseParentheses = true; }
public void Do () { Region.SetNeedToEvaluate (true); if (Region.Selection.SelectedToken is TextToken == false) { if (Region.Selection.Type == SelectionType.Right) { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); } } else { var textToken = Region.Selection.SelectedToken as TextToken; if (!string.IsNullOrEmpty (textToken.Text) && Region.Selection.Position != 0) { if (Regex.IsMatch (textToken.Text, @"^\D") && Region.Selection.Position == textToken.Text.Length) { var p = GetHBoxToken (textToken); var i = p.Tokens.IndexOf (textToken); p.Tokens.Insert (i + 1, new TextToken ()); new RightAction (Region).Do (); } else { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); } } } var parent = GetHBoxToken (Region.Selection.SelectedToken); var index = parent.Tokens.IndexOf (Region.Selection.SelectedToken); var newContainer = new HBoxToken (); foreach (var token in parent.Tokens.Skip (index).ToList()) { parent.Tokens.Remove (token); newContainer.Add (token); } var parenthess = new ParenthesesToken (); parenthess.Child = newContainer; parent.Tokens.Add (parenthess); }
public void Do () { var operation = new MultiplicationToken (); new InsertHBinaryOperation (Region, operation).Do (); }