예제 #1
0
        protected override void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Delete)
            {
                Block next = this.Next;
                if (MyTextBox.CaretIsAtEnd && next != null)
                {
                    if (next.Next != null)
                    {
                        TokenActions.DeleteSeparatorAndJoinNeighbours(next);
                    }
                    else
                    {
                        TokenActions.AppendLineBelowToCurrentLine(next);
                    }
                }
                e.Handled = true;
                //if (MyTextBox.CaretPosition == MyTextBox.Text.Length
                //    && this.Next != null
                //    && this.Next.Next != null)
                //{
                //    using (ActionBuilder a = new ActionBuilder(this.Root))
                //    {
                //        if (this.Next is SpaceBlock && this.Next.Next is TextBoxBlock)
                //        {
                //            string textToAppend = ((TextBoxBlock)this.Next.Next).Text;
                //            a.DeleteBlock(this.Next);
                //            a.DeleteBlock(this.Next.Next);
                //            a.RenameItem(this.MyTextBox, this.Text + textToAppend);
                //        }
                //        a.Run();
                //    }
                //}
            }

            if (e.KeyCode == System.Windows.Forms.Keys.Back)
            {
                Block prev = this.Prev;
                if (MyTextBox.CaretIsAtBeginning && prev != null)
                {
                    if (prev.Prev != null)
                    {
                        TokenActions.DeleteSeparatorAndJoinNeighbours(prev);
                    }
                    else
                    {
                        TokenActions.AppendSecondLineToFirst(prev);
                    }
                }
                e.Handled = true;
            }

            if (e.KeyCode == System.Windows.Forms.Keys.Return)
            {
                // ISeparatorToken next = this.Next as ISeparatorToken;
                if (MyTextBox.CaretIsAtEnd && this.Next != null)
                {
                    TokenActions.InsertNewLineFromCurrent(this.Next, TokenFactory.CreateNewLine());
                    e.Handled = true;
                }
            }

            if (e.KeyCode == System.Windows.Forms.Keys.Home)
            {
                TokenActions.SetCursorToTheBeginningOfLine(this);
                e.Handled = true;
            }

            if (e.KeyCode == System.Windows.Forms.Keys.End)
            {
                TokenActions.SetCursorToTheEndOfLine(this);
                e.Handled = true;
            }

            if (!e.Handled)
            {
                base.OnKeyDown(sender, e);
            }
        }