/// <summary> /// Returns a moving position and the suggestedX value for it. /// </summary> /// <param name="This">TextEditor</param> /// <param name="innerMovingPosition">Inner moving position if it has valid layout, otherwise null.</param> /// <returns>Returns suggestedX when moving position has valid layout, Double.NaN otherwise.</returns> private static Double GetSuggestedX(TextEditor This, out ITextPointer innerMovingPosition) { // When getting moving position, we need to take care of end-of-line case // and adjust moving position according to its orientation. innerMovingPosition = TextEditorSelection.GetMovingPositionInner(This); // We need a non-dirty layout to walk pages. if (!innerMovingPosition.ValidateLayout()) { innerMovingPosition = null; return Double.NaN; // This value is not supposed to be used by a caller. } if (Double.IsNaN(This._suggestedX)) { This._suggestedX = GetAbsoluteXOffset(This.TextView, innerMovingPosition); // If the original moving position is on the other side of a line break, // add in the pixel width of the line break visualization. // Note this logic implicitly only modifies suggested x when the // selection is non-empty. if (This.Selection.MovingPosition.CompareTo(innerMovingPosition) > 0) { double breakWidth = (double)innerMovingPosition.GetValue(TextElement.FontSizeProperty) * CaretElement.c_endOfParaMagicMultiplier; FlowDirection paragraphFlowDirection = GetScopingParagraphFlowDirection(innerMovingPosition); FlowDirection controlFlowDirection = This.UiScope.FlowDirection; if (paragraphFlowDirection != controlFlowDirection) { // Adjust for X-axis flip on Paragraphs with non-default flow direction. breakWidth = -breakWidth; } This._suggestedX += breakWidth; } } return This._suggestedX; }