public void Do ()
		{
			Region.SetNeedToEvaluate (true);

			var parent = Region.Selection.SelectedToken.Parent;

			Token _base;
			Token power;

			if (Region.Selection.SelectedToken is TextToken) {
				var textToken = Region.Selection.SelectedToken as TextToken;

				_base = new TextToken ()
				{
					Text = GetLeftString (textToken.Text)
				};

				power = new TextToken ()
				{
					Text = GetRightString (textToken.Text)
				};
			} else {
				if (Region.Selection.SelectedToken is FractionToken) {
					var fraction = Region.Selection.SelectedToken;

					var parentheses = new ParenthesesToken ();
					parentheses.ShowCloseParentheses = true;

					parent.Replace (fraction, parentheses);

					var container = new HBoxToken ();
					parentheses.Child = container;

					container.Add (fraction);

					_base = parentheses;
					Region.Selection.SelectedToken = parentheses;
				} else
					_base = Region.Selection.SelectedToken;

				power = new TextToken ();
			}

			var exponentiation = new ExponentiationToken ();			

			parent.Replace (Region.Selection.SelectedToken, exponentiation);
			exponentiation.Base = _base;
			exponentiation.Power = power;
				
			Region.Selection.SelectedToken = power;
		}
Example #2
0
		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);
		}