public override void Execute(TextArea textArea) { if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); return; } if (textArea.Caret.Offset > 0 && !textArea.IsReadOnly(textArea.Caret.Offset - 1)) { textArea.BeginUpdate(); int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); int offset = textArea.Document.GetLineSegment(lineNumberForOffset).Offset; if (offset != textArea.Caret.Offset) { int num = textArea.Caret.Offset - 1; textArea.Caret.Position = textArea.Document.OffsetToPosition(num); textArea.Document.Remove(num, 1); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new TextLocation(textArea.Caret.Offset - textArea.Document.GetLineSegment(lineNumberForOffset).Offset, lineNumberForOffset))); } else { LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset - 1); int totalNumberOfLines = textArea.Document.TotalNumberOfLines; int offset1 = lineSegment.Offset + lineSegment.Length; int length = lineSegment.Length; textArea.Document.Remove(offset1, offset - offset1); textArea.Caret.Position = new TextLocation(length, lineNumberForOffset - 1); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, lineNumberForOffset - 1))); } textArea.EndUpdate(); } }
public override void Execute(TextArea textArea) { if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); return; } textArea.BeginUpdate(); LineSegment lineSegmentForOffset = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset); if (textArea.Caret.Offset != lineSegmentForOffset.Offset + lineSegmentForOffset.Length) { int num = TextUtilities.FindNextWordStart(textArea.Document, textArea.Caret.Offset); if (num > textArea.Caret.Offset && !textArea.IsReadOnly(textArea.Caret.Offset, num - textArea.Caret.Offset)) { textArea.Document.Remove(textArea.Caret.Offset, num - textArea.Caret.Offset); } } else { base.Execute(textArea); } textArea.UpdateMatchingBracket(); textArea.EndUpdate(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset)))); textArea.Document.CommitUpdate(); }
public override void Execute(TextArea textArea) { if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); return; } if (textArea.IsReadOnly(textArea.Caret.Offset)) { return; } if (textArea.Caret.Offset < textArea.Document.TextLength) { textArea.BeginUpdate(); int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset); if (lineSegment.Offset + lineSegment.Length != textArea.Caret.Offset) { textArea.Document.Remove(textArea.Caret.Offset, 1); } else if (lineNumberForOffset + 1 < textArea.Document.TotalNumberOfLines) { LineSegment lineSegment1 = textArea.Document.GetLineSegment(lineNumberForOffset + 1); textArea.Document.Remove(textArea.Caret.Offset, lineSegment1.Offset - textArea.Caret.Offset); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, lineNumberForOffset))); } textArea.UpdateMatchingBracket(); textArea.EndUpdate(); } }
/// <remarks> /// Executes this edit action /// </remarks> /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param> public override void Execute(TextArea textArea) { if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); } else { if (textArea.Caret.Offset > 0 && !textArea.IsReadOnly(textArea.Caret.Offset - 1)) { textArea.BeginUpdate(); int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); int curLineOffset = textArea.Document.GetLineSegment(curLineNr).Offset; if (curLineOffset == textArea.Caret.Offset) { LineSegment line = textArea.Document.GetLineSegment(curLineNr - 1); int lineEndOffset = line.Offset + line.Length; int lineLength = line.Length; textArea.Document.Remove(lineEndOffset, curLineOffset - lineEndOffset); textArea.Caret.Position = new TextLocation(lineLength, curLineNr - 1); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr - 1))); } else { int caretOffset = textArea.Caret.Offset - 1; textArea.Caret.Position = textArea.Document.OffsetToPosition(caretOffset); textArea.Document.Remove(caretOffset, 1); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToLineEnd, new TextLocation(textArea.Caret.Offset - textArea.Document.GetLineSegment(curLineNr).Offset, curLineNr))); } textArea.EndUpdate(); } } }
/// <remarks> /// Executes this edit action /// </remarks> /// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param> public override void Execute(TextArea textArea) { // if anything is selected we will just delete it first if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); return; } textArea.BeginUpdate(); // now delete from the caret to the beginning of the word var line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset); // if we are not at the beginning of a line if (textArea.Caret.Offset > line.Offset) { var prevWordStart = TextUtilities.FindPrevWordStart( textArea.Document, textArea.Caret.Offset); if (prevWordStart < textArea.Caret.Offset) { if (!textArea.IsReadOnly(prevWordStart, textArea.Caret.Offset - prevWordStart)) { textArea.Document.Remove( prevWordStart, textArea.Caret.Offset - prevWordStart); textArea.Caret.Position = textArea.Document.OffsetToPosition(prevWordStart); } } } // if we are now at the beginning of a line if (textArea.Caret.Offset == line.Offset) { // if we are not on the first line var curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); if (curLineNr > 0) { // move to the end of the line above var lineAbove = textArea.Document.GetLineSegment(curLineNr - 1); var endOfLineAbove = lineAbove.Offset + lineAbove.Length; var charsToDelete = textArea.Caret.Offset - endOfLineAbove; if (!textArea.IsReadOnly(endOfLineAbove, charsToDelete)) { textArea.Document.Remove(endOfLineAbove, charsToDelete); textArea.Caret.Position = textArea.Document.OffsetToPosition(endOfLineAbove); } } } textArea.SetDesiredColumn(); textArea.EndUpdate(); // if there are now less lines, we need this or there are redraw problems textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(column: 0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset)))); textArea.Document.CommitUpdate(); }
public override void Execute(TextArea textArea) { if (textArea.SelectionManager.HasSomethingSelected) { Delete.DeleteSelection(textArea); return; } textArea.BeginUpdate(); LineSegment lineSegmentForOffset = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset); if (textArea.Caret.Offset > lineSegmentForOffset.Offset) { int num = TextUtilities.FindPrevWordStart(textArea.Document, textArea.Caret.Offset); if (num < textArea.Caret.Offset && !textArea.IsReadOnly(num, textArea.Caret.Offset - num)) { textArea.Document.Remove(num, textArea.Caret.Offset - num); textArea.Caret.Position = textArea.Document.OffsetToPosition(num); } } if (textArea.Caret.Offset == lineSegmentForOffset.Offset) { int lineNumberForOffset = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); if (lineNumberForOffset > 0) { LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumberForOffset - 1); int offset = lineSegment.Offset + lineSegment.Length; int offset1 = textArea.Caret.Offset - offset; if (!textArea.IsReadOnly(offset, offset1)) { textArea.Document.Remove(offset, offset1); textArea.Caret.Position = textArea.Document.OffsetToPosition(offset); } } } textArea.SetDesiredColumn(); textArea.EndUpdate(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset)))); textArea.Document.CommitUpdate(); }