public override void HandleKeyDown(UIKeyEventArgs e) { this.SetCaretVisible(true); if (!e.HasKeyData) { return; } switch (e.KeyCode) { case UIKeys.Home: { this.DoHome(e.Shift); } break; case UIKeys.End: { this.DoEnd(e.Shift); } break; case UIKeys.Back: { if (_isEditable) { if (_editSession.SelectionRange != null) { InvalidateGraphicOfCurrentSelectionArea(); } else { InvalidateGraphicOfCurrentLineArea(); } if (_textSurfaceEventListener == null) { _editSession.DoBackspace(); } else { if (!TextSurfaceEventListener.NotifyPreviewBackSpace(_textSurfaceEventListener, e) && _editSession.DoBackspace()) { TextSurfaceEventListener.NotifyCharactersRemoved(_textSurfaceEventListener, new TextDomEventArgs(_editSession._updateJustCurrentLine)); } } EnsureCaretVisible(); } } break; case UIKeys.Delete: { if (_isEditable) { if (_editSession.SelectionRange != null) { InvalidateGraphicOfCurrentSelectionArea(); } else { InvalidateGraphicOfCurrentLineArea(); } if (_textSurfaceEventListener == null) { _editSession.DoDelete(); } else { VisualSelectionRangeSnapShot delpart = _editSession.DoDelete(); TextSurfaceEventListener.NotifyCharactersRemoved(_textSurfaceEventListener, new TextDomEventArgs(_editSession._updateJustCurrentLine, delpart)); } EnsureCaretVisible(); } } break; default: { if (_textSurfaceEventListener != null) { UIKeys keycode = e.KeyCode; if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12) { InvalidateGraphicOfCurrentSelectionArea(); TextSurfaceEventListener.NotifyFunctionKeyDown(_textSurfaceEventListener, keycode); EnsureCaretVisible(); } } } break; } if (e.HasKeyData && e.Ctrl) { switch (e.KeyCode) { case UIKeys.A: { //select all //.... this.CurrentLineNumber = 0; //start select to end DoHome(false); //1st simulate DoHome(true); //2nd this.CurrentLineNumber = this.LineCount - 1; DoEnd(true); // } break; case UIKeys.C: { using (StringBuilderPool <TempTextLineCopyContext> .GetFreeStringBuilder(out StringBuilder stBuilder)) { _editSession.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { if (stBuilder.Length == 0) { Clipboard.Clear(); } else { Clipboard.SetText(stBuilder.ToString()); } } } } break; case UIKeys.V: { if (_isEditable && Clipboard.ContainsUnicodeText()) { //1. we need to parse multi-line to single line //this may need text-break services _editSession.AddTextToCurrentLine(PlainTextDocumentHelper.CreatePlainTextDocument(Clipboard.GetUnicodeText())); EnsureCaretVisible(); } } break; case UIKeys.X: { if (_isEditable && _editSession.SelectionRange != null) { InvalidateGraphicOfCurrentSelectionArea(); using (StringBuilderPool <TempTextLineCopyContext> .GetFreeStringBuilder(out StringBuilder stBuilder)) { _editSession.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { Clipboard.SetText(stBuilder.ToString()); } _editSession.DoDelete(); EnsureCaretVisible(); } } } break; case UIKeys.Z: { if (_isEditable) { _editSession.UndoLastAction(); EnsureCaretVisible(); } } break; case UIKeys.Y: { if (_isEditable) { _editSession.ReverseLastUndoAction(); EnsureCaretVisible(); } } break; } } if (_textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(_textSurfaceEventListener, e); } }