private void DocumentEditor_SelectionChanged(object sender, RoutedEventArgs e) { TextPointer ls = CaretPosition.GetLineStartPosition(0); TextPointer p = Document.ContentStart.GetLineStartPosition(0); int @int = 1; int int2 = 1; while (true) { if (ls.CompareTo(p) < 1) { break; // TODO: might not be correct. Was : Exit While } int r = 0; p = p.GetLineStartPosition(1, out r); if (r == 0) { break; // TODO: might not be correct. Was : Exit While } @int += 1; } TextPointer ls2 = Document.ContentStart.DocumentEnd.GetLineStartPosition(0); TextPointer p2 = Document.ContentEnd.DocumentStart.GetLineStartPosition(0); while (true) { if (ls2.CompareTo(p2) < 1) { break; // TODO: might not be correct. Was : Exit While } int r = 0; p2 = p2.GetLineStartPosition(1, out r); if (r == 0) { break; // TODO: might not be correct. Was : Exit While } int2 += 1; } SelectedLineNumber = @int; LineCount = int2; TextRange t = new TextRange(Document.ContentStart, Document.ContentEnd); TextPointer caretPos = CaretPosition; TextPointer poi = CaretPosition.GetLineStartPosition(0); int currentColumnNumber = Math.Max(p.GetOffsetToPosition(caretPos) - 1, 0) + 1; int currentColumnCount = currentColumnNumber; currentColumnCount += CaretPosition.GetTextRunLength(System.Windows.Documents.LogicalDirection.Forward); SelectedColumnNumber = currentColumnNumber; ColumnCount = currentColumnCount; }
private void AppendContainer(Inline container) { _suppressRecognition = true; CaretPosition = CaretPosition.DocumentEnd; var length = CaretPosition.GetTextRunLength(LogicalDirection.Backward); CaretPosition = CaretPosition.GetPositionAtOffset(-length); if (CaretPosition != null) { CaretPosition.DeleteTextInRun(length); var paragraph = CaretPosition.Paragraph; if (paragraph != null) { paragraph.Inlines.Add(container); } CaretPosition = CaretPosition.DocumentEnd; } _suppressRecognition = false; }