Line fragment rect is always 14pt high in default -[NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:]

Originator:christian.tietze
Number:rdar://36581248 Date Originated:2018-01-17
Status:Open Resolved:
Product:macOS + SDK Product Version:
Classification:UI/Usability Reproducible:always
 
Summary:

When deleting at the end of the last line of text which is also the second line of text overall, with the first line being empty (i.e. only a newline character), the insertion point is drawn too far to the top. The NSLayoutManager computes a wrong line height.


Steps to Reproduce:

(1) Configure a NSTextView to have non-default line heights, e.g. using a larger font size
(2) Replace the text with an empty line and type in the second line, note how the insertion point is drawn correctly
(3) delete from the end of the second line with backspace; note that the insertion point's height is appropriate, but its Y-coordinate is off

In code:

    textView.font = NSFont.systemFont(ofSize: 30)
    textView.insertText("\nhit backspace at the end of this paragraph; note that the print'ed lineFragmentRect.height is 14 until you enter something into the first line", replacementRange: NSRange())


Expected Results:

When deleting with backspace at the end of the second (and last) line of text, the insertion point should stay in line and move back horizontally.

Actual Results:

The insertion point moves back horizontally by the width of the deleted character but also some pixels to the top.

Version/Build:

Xcode Version 9.2 (9C40b)
macOS SDK 10.13

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!