public static void Paste(TextEditorData data) { if (!data.CanEditSelection) { return; } LineSegment line = data.Document.GetLine(data.Caret.Line); if (data.Caret.Column > line.EditableLength + 1) { string text = data.GetVirtualSpaces(data.Caret.Line, data.Caret.Column); int offset = data.Caret.Offset; int textLength = data.Insert(offset, text); data.Caret.Offset = offset + textLength; } PasteFrom(Clipboard.Get(CopyOperation.CLIPBOARD_ATOM), data, true, data.IsSomethingSelected ? data.SelectionRange.Offset : data.Caret.Offset); }
public static void Paste (TextEditorData data) { if (!data.CanEditSelection) return; LineSegment line = data.Document.GetLine (data.Caret.Line); if (data.Caret.Column > line.EditableLength + 1) { string text = data.GetVirtualSpaces (data.Caret.Line, data.Caret.Column); int offset = data.Caret.Offset; int textLength = data.Insert (offset, text); data.Caret.Offset = offset + textLength; } PasteFrom (Clipboard.Get (CopyOperation.CLIPBOARD_ATOM), data, true, data.IsSomethingSelected ? data.SelectionRange.Offset : data.Caret.Offset); }
protected void InsertCharacter(uint unicodeKey) { if (!textEditorData.CanEdit(Data.Caret.Line)) { return; } HideMouseCursor(); using (var undo = Document.OpenUndoGroup()) { textEditorData.DeleteSelectedText(textEditorData.IsSomethingSelected ? textEditorData.MainSelection.SelectionMode != SelectionMode.Block : true); char ch = (char)unicodeKey; if (!char.IsControl(ch) && textEditorData.CanEdit(Caret.Line)) { LineSegment line = Document.GetLine(Caret.Line); if (Caret.IsInInsertMode || Caret.Column >= line.EditableLength + 1) { string text = Caret.Column > line.EditableLength + 1 ? textEditorData.GetVirtualSpaces(Caret.Line, Caret.Column) + ch.ToString() : ch.ToString(); if (textEditorData.IsSomethingSelected && textEditorData.MainSelection.SelectionMode == SelectionMode.Block) { int length = 0; var visualInsertLocation = editor.LogicalToVisualLocation(Caret.Location); for (int lineNumber = textEditorData.MainSelection.MinLine; lineNumber <= textEditorData.MainSelection.MaxLine; lineNumber++) { LineSegment lineSegment = textEditorData.GetLine(lineNumber); int insertOffset = lineSegment.GetLogicalColumn(textEditorData, visualInsertLocation.Column) - 1; string textToInsert; if (lineSegment.EditableLength < insertOffset) { int visualLastColumn = lineSegment.GetVisualColumn(textEditorData, lineSegment.EditableLength + 1); int charsToInsert = visualInsertLocation.Column - visualLastColumn; int spaceCount = charsToInsert % editor.Options.TabSize; textToInsert = new string ('\t', (charsToInsert - spaceCount) / editor.Options.TabSize) + new string (' ', spaceCount) + text; insertOffset = lineSegment.EditableLength; } else { textToInsert = text; } length = textEditorData.Insert(lineSegment.Offset + insertOffset, textToInsert); } Caret.PreserveSelection = true; Caret.Column += length - 1; textEditorData.MainSelection.Lead = new DocumentLocation(textEditorData.MainSelection.Lead.Line, Caret.Column + 1); textEditorData.MainSelection.Anchor = new DocumentLocation(textEditorData.MainSelection.Anchor.Line, Caret.Column + 1); Document.CommitMultipleLineUpdate(textEditorData.MainSelection.MinLine, textEditorData.MainSelection.MaxLine); } else { int length = textEditorData.Insert(Caret.Offset, text); Caret.Column += length - 1; } } else { int length = textEditorData.Replace(Caret.Offset, 1, ch.ToString()); if (length > 1) { Caret.Offset += length - 1; } } // That causes unnecessary redraws: // bool autoScroll = Caret.AutoScrollToCaret; Caret.Column++; if (Caret.PreserveSelection) { Caret.PreserveSelection = false; } // Caret.AutoScrollToCaret = autoScroll; // if (autoScroll) // Editor.ScrollToCaret (); // Document.RequestUpdate (new LineUpdate (Caret.Line)); // Document.CommitDocumentUpdate (); } } Document.OptimizeTypedUndo(); }
protected void InsertCharacter(uint unicodeKey) { if (!textEditorData.CanEdit(Data.Caret.Line)) { return; } HideMouseCursor(); Document.BeginAtomicUndo(); if (textEditorData.IsSomethingSelected && textEditorData.MainSelection.SelectionMode == SelectionMode.Block) { textEditorData.Caret.PreserveSelection = true; if (!textEditorData.MainSelection.IsDirty) { textEditorData.DeleteSelectedText(false); textEditorData.MainSelection.IsDirty = true; } } else { textEditorData.DeleteSelectedText(); } char ch = (char)unicodeKey; if (!char.IsControl(ch) && textEditorData.CanEdit(Caret.Line)) { LineSegment line = Document.GetLine(Caret.Line); if (Caret.IsInInsertMode || Caret.Column >= line.EditableLength) { string text = Caret.Column > line.EditableLength ? textEditorData.GetVirtualSpaces(Caret.Line, Caret.Column) + ch.ToString() : ch.ToString(); if (textEditorData.IsSomethingSelected && textEditorData.MainSelection.SelectionMode == SelectionMode.Block) { int length = 0; for (int lineNumber = textEditorData.MainSelection.MinLine; lineNumber <= textEditorData.MainSelection.MaxLine; lineNumber++) { length = textEditorData.Insert(textEditorData.Document.GetLine(lineNumber).Offset + Caret.Column, text); } Caret.Column += length - 1; textEditorData.MainSelection.Lead = new DocumentLocation(textEditorData.MainSelection.Lead.Line, Caret.Column + 1); textEditorData.MainSelection.IsDirty = true; Document.CommitMultipleLineUpdate(textEditorData.MainSelection.MinLine, textEditorData.MainSelection.MaxLine); } else { int length = textEditorData.Insert(Caret.Offset, text); Caret.Column += length - 1; } } else { int length = textEditorData.Replace(Caret.Offset, 1, ch.ToString()); if (length > 1) { Caret.Offset += length - 1; } } // That causes unnecessary redraws: // bool autoScroll = Caret.AutoScrollToCaret; Caret.Column++; // Caret.AutoScrollToCaret = autoScroll; // if (autoScroll) // Editor.ScrollToCaret (); // Document.RequestUpdate (new LineUpdate (Caret.Line)); // Document.CommitDocumentUpdate (); } if (textEditorData.IsSomethingSelected && textEditorData.MainSelection.SelectionMode == SelectionMode.Block) { textEditorData.Caret.PreserveSelection = false; } Document.EndAtomicUndo(); Document.OptimizeTypedUndo(); }