public override void InvokeUndo(InternalTextLayerController textdom) { textdom.CurrentLineNumber = startLineNumber; textdom.CharIndex = startCharIndex; textdom.DoBackspace(); }
public override void InvokeUndo(InternalTextLayerController textLayer) { textLayer.CurrentLineNumber = startLineNumber; textLayer.TryMoveCaretTo(startCharIndex); textLayer.DoBackspace(); }
public void HandleKeyDown(UIKeyEventArgs e) { this.SetCaretState(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 (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoBackspace(); } else { if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) && internalTextLayerController.DoBackspace()) { TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } } EnsureCaretVisible(); } break; case UIKeys.Delete: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoDelete(); } else { VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete(); TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } EnsureCaretVisible(); } break; default: { if (textSurfaceEventListener != null) { UIKeys keycode = e.KeyCode; if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); 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 DoEnd(true); //simulate this.CurrentLineNumber = this.LineCount - 1; DoEnd(true); } break; case UIKeys.C: { StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { if (stBuilder.Length == 0) { Clipboard.Clear(); } else { Clipboard.SetText(stBuilder.ToString()); } } ReleaseStringBuilder(stBuilder); } break; case UIKeys.V: { if (Clipboard.ContainUnicodeText()) { //1. we need to parse multi-line to single line //this may need text-break services internalTextLayerController.AddUnformattedStringToCurrentLine( Clipboard.GetUnicodeText(), this.currentSpanStyle); EnsureCaretVisible(); } } break; case UIKeys.X: { if (internalTextLayerController.SelectionRange != null) { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { Clipboard.SetText(stBuilder.ToString()); } internalTextLayerController.DoDelete(); EnsureCaretVisible(); ReleaseStringBuilder(stBuilder); } } break; case UIKeys.Z: { internalTextLayerController.UndoLastAction(); EnsureCaretVisible(); } break; case UIKeys.Y: { internalTextLayerController.ReverseLastUndoAction(); EnsureCaretVisible(); } break; case UIKeys.B: { // //test add markers // //if (internalTextLayerController.SelectionRange != null) //{ // // // internalTextLayerController.SelectionRange.SwapIfUnOrder(); // VisualMarkerSelectionRange markerSelRange = // VisualMarkerSelectionRange.CreateFromSelectionRange( // internalTextLayerController.SelectionRange.GetSelectionRangeSnapshot()); // //then add to the marker layers // markerSelRange.BindToTextLayer(textLayer); // internalTextLayerController.VisualMarkers.Add(markerSelRange); //} // //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange(); //TextSpanStyle textStyle = null; ////test only *** ////TODO: make this more configurable //if (style != null) //{ // TextSpanStyle defaultBeh = ((TextSpanStyle)style); // if (defaultBeh.FontBold) // { // textStyle = StyleHelper.CreateNewStyle(Color.Black); // } // else // { // textStyle = StyleHelper.CreateNewStyle(Color.Blue); // } //} //else //{ // textStyle = StyleHelper.CreateNewStyle(Color.Blue); //} //internalTextLayerController.DoFormatSelection(textStyle); //if (internalTextLayerController.updateJustCurrentLine) //{ // InvalidateGraphicOfCurrentLineArea(); //} //else //{ // InvalidateGraphics(); //} } break; } } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode); } }
public void OnKeyDown(UIKeyEventArgs e) { this.SetCaretState(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 (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoBackspace(); } else { if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) && internalTextLayerController.DoBackspace()) { TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } } EnsureCaretVisible(); } break; case UIKeys.Delete: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoDelete(); } else { VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete(); TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } EnsureCaretVisible(); } break; default: { if (textSurfaceEventListener != null) { UIKeys keycode = e.KeyCode; if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); TextSurfaceEventListener.NotifyFunctionKeyDown(textSurfaceEventListener, keycode); EnsureCaretVisible(); } } } break; } if (e.HasKeyData && e.Ctrl) { switch (e.KeyCode) { case UIKeys.C: { StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { if (stBuilder.Length == 0) { Clipboard.Clear(); } else { Clipboard.SetText(stBuilder.ToString()); } } ReleaseStringBuilder(stBuilder); } break; case UIKeys.V: { if (Clipboard.ContainUnicodeText()) { internalTextLayerController.AddTextRunsToCurrentLine( new EditableRun[] { new EditableTextRun(this.Root, Clipboard.GetUnicodeText(), this.CurrentTextSpanStyle) }); EnsureCaretVisible(); } } break; case UIKeys.X: { if (internalTextLayerController.SelectionRange != null) { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { Clipboard.SetText(stBuilder.ToString()); } internalTextLayerController.DoDelete(); EnsureCaretVisible(); ReleaseStringBuilder(stBuilder); } } break; case UIKeys.Z: { internalTextLayerController.UndoLastAction(); EnsureCaretVisible(); } break; case UIKeys.Y: { internalTextLayerController.ReverseLastUndoAction(); EnsureCaretVisible(); } break; case UIKeys.B: { //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange(); //TextSpanStyle textStyle = null; ////test only *** ////TODO: make this more configurable //if (style != null) //{ // TextSpanStyle defaultBeh = ((TextSpanStyle)style); // if (defaultBeh.FontBold) // { // textStyle = StyleHelper.CreateNewStyle(Color.Black); // } // else // { // textStyle = StyleHelper.CreateNewStyle(Color.Blue); // } //} //else //{ // textStyle = StyleHelper.CreateNewStyle(Color.Blue); //} //internalTextLayerController.DoFormatSelection(textStyle); //if (internalTextLayerController.updateJustCurrentLine) //{ // InvalidateGraphicOfCurrentLineArea(); //} //else //{ // InvalidateGraphics(); //} } break; } } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode); } }