public void Cut(object sender, EventArgs e) { if (textArea.SelectionManager.HasSomethingSelected) { if (CopyTextToClipboard(textArea.SelectionManager.SelectedText)) { if (textArea.SelectionManager.SelectionIsReadonly) { return; } textArea.BeginUpdate(); textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition; textArea.SelectionManager.RemoveSelectedText(); textArea.EndUpdate(); } } else if (textArea.Document.TextEditorProperties.CutCopyWholeLine) { int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr); string caretLineText = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength); textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength)); if (CopyTextToClipboard(caretLineText, true)) { if (textArea.SelectionManager.SelectionIsReadonly) { return; } textArea.BeginUpdate(); textArea.Caret.Position = textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset); textArea.SelectionManager.RemoveSelectedText(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr))); textArea.EndUpdate(); } } }
protected void OnDragDrop(object sender, DragEventArgs e) { Point p = textArea.PointToClient(new Point(e.X, e.Y)); if (e.Data.GetDataPresent(typeof(string))) { textArea.BeginUpdate(); textArea.Document.UndoStack.StartUndoGroup(); try { int offset = textArea.Caret.Offset; if (textArea.IsReadOnly(offset)) { return; } if (e.Data.GetDataPresent(typeof(DefaultSelection))) { ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } if (GetDragDropEffect(e) == DragDropEffects.Move) { if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel)) { return; } int len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } } textArea.SelectionManager.ClearSelection(); InsertString(offset, (string)e.Data.GetData(typeof(string))); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.EndUpdate(); } } }