diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs index 86addb9d09c..c7a87170634 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs @@ -607,8 +607,11 @@ private void ExpandToEnclosingUnit(TextUnit unit, bool expandStart, bool expandE _start = lineRange.Start.CreatePointer(); } // If this line contains also end position, move it to the - // end of this line. - if (lineRange.Contains(_end)) + // end of this line. Also handle blank/empty lines where + // lineRange.Start == lineRange.End (ContentLength == 0): + // snap _end to the blank line boundary so expandEnd doesn't + // bleed into the next line. + if (lineRange.Contains(_end) || lineRange.Start.CompareTo(lineRange.End) == 0) { snapEndPosition = false; if (_end.CompareTo(lineRange.End) != 0)