开发者

NSTextView lineHeightMultiple drawing issues

By setting the lineHeightMultiple of a NSParagraphStyle that is used in a text view I'm getting drawing artifacts when selecting text. This is reproducible in TextEdit. More specifically:

  1. Open TextEdit in rich text mode
  2. Pick Courier 14 as the font
  3. Set line height multiple to 1.4
  4. Insert a bunch of text
  5. Select a portion of text with the mouse until the top
  6. Start decreasing the selection (moving the mouse down)

In some lines, the selection is not totally cleared, leaving a 1px horizontal artifact behind (see screnshot). This also occurs with different fonts, font sizes as lineHeightM开发者_开发百科ultiple values (although not all).

Has anyone experience this or has any idea why this is happening?

Thanks,

Rúben

NSTextView lineHeightMultiple drawing issues


I fixed this in my own code by adding the paragraph style to the selected text attributes, and rounding the line height.

NSTextView lineHeightMultiple drawing issues


I had a similar issue with NSTextAttachment's which were having a height larger than the default line spacing. I was able to mitigate it by adding this line to my NSTextViewDelegate.

func textViewDidChangeSelection(_ notification: Notification) {
    // will fix artifacts after releasing mouse button
    self.textView.needsDisplay = true
}

I also tried to create a larger redraw area during mouseDragged in my custom NSTextView class, but unfortunately NSTextView is handling this completely different, thus mouseDragged is never being invoked.

The trick with the paragraph style did not work for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜