void SetUndoDelete(int pos, int delLen) { UndoRedoManager.Do(new UndoRedoDeleteMemento { ScrollOffset = ScrollOffset, SelStart = SelStart, SelLength = SelLength, SelectedText = SelectedText, Position = pos, Data = RowManager.GetCharRange(pos, delLen), }); }
public void Copy() { if (!CanCopy) { return; } string content = RowManager.GetCharRange(SelStart, SelLength); PlatformExtensions.SetClipboardText(content); Modified = true; }
// *** Clipboard *** public void Cut() { if (!CanCut) { return; } int pos = RowManager.AbsCursorPosition; this.SetUndoDelete(pos, 0); string content = RowManager.GetCharRange(SelStart, SelLength); DeleteSelection(); PlatformExtensions.SetClipboardText(content); ResetSelection(); Invalidate(); }
public override bool OnKeyDown(KeyboardKeyEventArgs e) { if (ModifierKeys.AltPressed || !IsFocused) { return(false); } //Console.WriteLine (e.Key); //if (base.OnKeyDown (e)) // return false; switch (e.Key) { case Key.ShiftLeft: case Key.ShiftRight: //if (SelLength == 0) // SelStart = RowManager.AbsCursorPosition; return(true); case Key.Left: if (e.Control) { RowManager.MovePrevWord(); } else { RowManager.MovePrevChar(); } SetSelection(e.Shift); break; case Key.Right: if (e.Control) { RowManager.MoveNextWord(); } else { RowManager.MoveNextChar(); } SetSelection(e.Shift); break; case Key.Up: if (e.Control) { ScrollLineUp(); return(true); } else { RowManager.MovePrevLine(); SetSelection(e.Shift); } break; case Key.Down: if (e.Control) { ScrollLineDown(); return(true); } else { RowManager.MoveNextLine(); SetSelection(e.Shift); } break; case Key.Home: if (e.Control) { RowManager.MoveHome(); } else { RowManager.MoveParagraphHome(); } SetSelection(e.Shift); break; case Key.End: if (e.Control) { RowManager.MoveEnd(); } else { RowManager.MoveParagraphEnd(); } SetSelection(e.Shift); break; case Key.PageUp: if (e.Control) { return(false); } RowManager.MovePageUp((int)((Height - Padding.Height) / RowManager.LineHeight)); SetSelection(e.Shift); break; case Key.PageDown: if (e.Control) { return(false); } RowManager.MovePageDown((int)((Height - Padding.Height) / RowManager.LineHeight)); SetSelection(e.Shift); break; case Key.BackSpace: if (SelLength > 0) { //this.SetUndoDelete (RowManager.AbsCursorPosition, 0); Delete(); } else { int pos = RowManager.AbsCursorPosition; UndoRedoManager.Do(new UndoRedoBackspaceMemento { ScrollOffset = ScrollOffset, SelStart = SelStart, SelLength = SelLength, SelectedText = SelectedText, Position = pos - 1, Data = RowManager.GetCharRange(pos - 1, 1), }); RowManager.DeletePrevChar(); } ResetSelection(); SetupDocumentSize(); break; case Key.Enter: SetUndoInsert("\n"); if (SelLength > 0) { DeleteSelection(); SelLength = 0; } RowManager.InsertLineBreak(); SetupDocumentSize(); break; case Key.C: if (e.Control) { Copy(); } break; case Key.V: if (e.Control) { Paste(); } break; case Key.X: if (e.Control) { Cut(); } break; case Key.Delete: if (e.Shift) { Cut(); } else { Delete(); } SetupDocumentSize(); break; case Key.Insert: if (e.Control) { Copy(); } else if (e.Shift) { Paste(); } break; case Key.A: if (e.Control) { SelectAll(); } break; case Key.F: if (e.Control) { Find(); } break; case Key.Y: // OpenTK sends an Y for a Z if (e.Control) { Undo(); } break; case Key.Z: // OpenTK sends an Z for a Y if (e.Control) { Redo(); } break; case Key.Escape: if (HideSelection) { SelectNone(); } return(false); /*** * case Key.Tab: * if (!AllowTabKey) * return false; * InsertString (CursorPosition++, new String (' ', 4)); * CursorPosition += 3; * break; ***/ default: //this.LogDebug ("OnKeyDown not handled: {0}", e.Key.ToString ()); // F10 //return false; break; } CursorOn = true; EnsureCurrentRowVisible(); Invalidate(); return(true); }