public override void Execute() { commandsByRanges.Clear(); var prevSelection = range.Clone(); var iChar = -1; var iStartLine = prevSelection.Start.iLine; var iEndLine = prevSelection.End.iLine; ts.CurrentTB.Selection.ColumnSelectionMode = false; ts.CurrentTB.Selection.BeginUpdate(); ts.CurrentTB.BeginUpdate(); ts.CurrentTB.allowInsertRemoveLines = false; try { if (cmd is InsertTextCommand) { ExecuteInsertTextCommand(ref iChar, (cmd as InsertTextCommand).insertedText); } else if (cmd is InsertCharCommand && (cmd as InsertCharCommand).c != '\x0' && (cmd as InsertCharCommand).c != '\b') //if not DEL or BACKSPACE { ExecuteInsertTextCommand(ref iChar, (cmd as InsertCharCommand).c.ToString()); } else { ExecuteCommand(ref iChar); } } catch (ArgumentOutOfRangeException) { } finally { ts.CurrentTB.allowInsertRemoveLines = true; ts.CurrentTB.EndUpdate(); ts.CurrentTB.Selection = range; if (iChar >= 0) { ts.CurrentTB.Selection.Start = new Place(iChar, iStartLine); ts.CurrentTB.Selection.End = new Place(iChar, iEndLine); } ts.CurrentTB.Selection.ColumnSelectionMode = true; ts.CurrentTB.Selection.EndUpdate(); } }
/// <summary> /// Returns union with other range. /// </summary> /// <param name="range"></param> /// <returns></returns> public Range GetUnionWith(Range range) { Range r1 = this.Clone(); Range r2 = range.Clone(); r1.Normalize(); r2.Normalize(); Place newStart = r1.Start < r2.Start ? r1.Start : r2.Start; Place newEnd = r1.End > r2.End ? r1.End : r2.End; return(tb.GetRange(newStart, newEnd)); }
/// <summary> /// Returns intersection with other range, /// empty range returned otherwise /// </summary> /// <param name="range"></param> /// <returns></returns> public virtual Range GetIntersectionWith(Range range) { if (ColumnSelectionMode) { return(GetIntersectionWith_ColumnSelectionMode(range)); } Range r1 = this.Clone(); Range r2 = range.Clone(); r1.Normalize(); r2.Normalize(); Place newStart = r1.Start > r2.Start ? r1.Start : r2.Start; Place newEnd = r1.End < r2.End ? r1.End : r2.End; if (newEnd < newStart) { return(new Range(tb, start, start)); } return(tb.GetRange(newStart, newEnd)); }