NSTextView not refreshed properly on scrolling
Asked Answered
G

5

7

I have a NSTextView with a sizeable quantity of text. Whenever I scroll however, the view isn't updated properly. There are some artifacts that remain at the top or the bottom of the view. It appears that the view doesn't refresh itself often enough. If I scroll very slowly the view updates correctly though. If I add a border to the view everything works perfectly, borderless view is the one that has a problem. Here's a link to a screenshot:

Thanks

Gasman answered 11/5, 2009 at 19:27 Comment(2)
Can anyone explain why has this question has been downvoted? It seems like a reasonable question to me.Streamlet
dw I upvoted to counter :P +1Carr
S
6

Have you set the setDrawsBackground and copiesOnScroll propertes for either the NSScrollView or the NSClipView?

The first thing I would suggest is turning off the "draws background" property of the NSScrollView:

[myScrollView setDrawsBackground:NO];

Note that this should be set on the NSScrollView, and not on the embedded NSClipView.

The following excerpt from the documentation may be relevant:

If your NSScrollView encloses an NSClipView sending a setDrawsBackground: message with a parameter of NO to the NSScrollView has the added effect of sending the NSClipView a setCopiesOnScroll: message with a parameter of NO. The side effect of sending the setDrawsBackground: message directly to the NSClipView instead would be the appearance of “trails” (vestiges of previous drawing) in the document view as it is scrolled.

Streamlet answered 28/5, 2009 at 18:55 Comment(1)
I just ran across this exact problem myself. Setting [scrollView setDrawsBackground:YES] fixed the artifact problem. In other news, it is a very strange feeling to find your own answer when searching for a solution :)Streamlet
C
2

Looks like the text field isn't even in the scrolling-area... Are you sure something isnt overlapping it?

Carillo answered 24/5, 2009 at 4:8 Comment(2)
I'm not sure, no. If I scroll downwards though, the text will appear, aligned with the bottom of the scroll control. The garbage will disappear, replaced with clear rendering of the text.Gasman
did you try re-setting up your xib? Sometimes that helps me.Carillo
B
1

I had a similar trouble - artifacts develop when the NSTextView is embedded in another scrollview (ie. a NSTableView).

I actually turned on the setdrawsbackground, and then added a nice color to make it disappear again.

-(void)awakeFromNib{
    NSScrollView *scroll = [self enclosingScrollView];
    [scroll setBorderType:NSNoBorder];
    [scroll setDrawsBackground:YES];
    [scroll setBackgroundColor:[NSColor windowBackgroundColor]];
}

This in combination with a scrollWheel event let me use the NSTextView in a NSTableView.

-(void)scrollWheel:(NSEvent *)theEvent{
    NSScrollView *scroll = [self enclosingScrollView];
   [[scroll superview] scrollWheel:theEvent];
}
Brassiere answered 7/1, 2015 at 19:58 Comment(0)
G
0

I had the same trouble some time ago. I don't remember how I solved it.

Try to place the NSTextView to another view if the superview is a custom view. Just to see what will happen.

Granny answered 25/5, 2009 at 23:4 Comment(1)
I'll give that a go. Good to know that I'm not the only one with this problem though.Gasman
P
0

I had a similar problem, what worked for me was setting this:

textView.layoutManager?.allowsNonContiguousLayout = false
Penrose answered 28/9, 2024 at 12:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.