TextEdit/NSTextView: line height changes when typing after an inline image

263 Views Asked by At

I have a Mac app with an embedded rich-text NSTextView, but the same problem can be reproduced with TextEdit:

  • When a line contains only an image and no text, typing right after the image causes the text below to move downwards.

TextEdit

  1. Open a new TextEdit document and type "test", [return]
  2. Cmd-Shift-Ctrl-4 to capture a screenshot of something
  3. Paste the image on the next line
  4. [return], type "test"
  5. Now type something after the image

To debug this in my app I added some code to highlight each line fragment rect via NSLayoutManager:

Custom app with NSTextView

The height of line 2 starts out at 14pt, as soon as I type a letter, it changes to 18pt.

Is this a bug in TextKit or a problem with incorrect/missing NSAttributedString attributes in my code?

I tried setting a paragraph style and font for my inline image, as well as a default paragraph style for the NSTextView, but the problem still occurs.

0

There are 0 best solutions below