Example #1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == Key.Left)
            {
                if (CurrPlace.CharNum > 0)
                {
                    CurrPlace = CurrPlace.Offset(0, -1);
                }
            }
            else if (e.Key == Key.Right)
            {
                if (CurrPlace.LineNum < Lines.Count && CurrPlace.CharNum < Lines[CurrPlace.LineNum].Content.Length)
                {
                    CurrPlace = CurrPlace.Offset(0, 1);
                }
            }
            else if (e.Key == Key.Up)
            {
                if (CurrPlace.LineNum > 0)
                {
                    CurrPlace = CurrPlace.Offset(-1, 0);
                }
            }
            else if (e.Key == Key.Down)
            {
                if (CurrPlace.LineNum < Lines.Count - 1)
                {
                    CurrPlace = CurrPlace.NextLine();
                }
            }
        }
Example #2
0
        protected override void OnTextInput(TextCompositionEventArgs e)
        {
            base.OnTextInput(e);

            var t = TextMapEngine.Instance.Map(e.Text);

            if (CurrPlace.LineNum >= Lines.Count)
            {
                Lines.Lines.Add(new Document.Line {
                    Source = Text, BeginPoint = Text.Length,
                });
            }

            if (e.Text == "\b")
            {
                if (Text.Length > 0 && Lines[CurrPlace.LineNum].BeginPoint + CurrPlace.CharNum > 0)
                {
                    int offset   = 1;
                    var newPlace = Place.Zero;
                    if (CurrPlace.CharNum == 0)
                    {
                        offset   = LineBreakHolder.CurrLineBreak.Length;
                        newPlace = CurrPlace.LastLine(Lines[CurrPlace.LineNum - 1].Content.Length);
                    }
                    else
                    {
                        newPlace = CurrPlace.Offset(0, -offset);
                    }
                    Text      = Text.Remove(Lines[CurrPlace.LineNum].BeginPoint + CurrPlace.CharNum - offset, offset);
                    CurrPlace = newPlace;
                }
            }
            else
            {
                Text = Text.Insert(Lines[CurrPlace.LineNum].BeginPoint + CurrPlace.CharNum, t);

                if (t == LineBreakHolder.CurrLineBreak)
                {
                    CurrPlace = CurrPlace.NextLine();
                }
                else
                {
                    CurrPlace = CurrPlace.Offset(0, t.Length);
                }
            }
        }