public CellString GetText(int offset, int length) { VerifyAccess(); var cells = new CellString(length); // Get the line the contains 'offset' var line = LineByOffset(offset); var i = offset - line.BegOffset; for (; line != null; line = line.NextLine, i = 0) { // Insert newline delimiters between lines if (cells.Length != 0) { var len = Math.Min(length, LineEnd.Length); cells.Append(LineEnd, 0, len); length -= len; } // Insert text from 'line' { var len = Math.Min(length, line.Length); cells.Append(line, i, len); length -= len; } } return(cells); }
/// <summary>Gets the selected text.</summary> public virtual CellString GetText() { var doc = TextArea.Document; if (doc == null) { throw new Exception("No associated TextDocument"); } var iter = Segments.GetEnumerator(); // No segments if (!iter.MoveNext()) { return(CellString.Empty); } // If there is only one segment, return the text directly var text = doc.GetText(iter.Current); if (!iter.MoveNext()) { return(text); } // Otherwise, combine text from the segments var cstr = new CellString(text) { Capacity = Length }; for (var more = true; more; more = iter.MoveNext()) { cstr.Append(doc.GetText(iter.Current)); } return(cstr); }