I have a problem with rulers in an NSTextView. My code has worked fine from about Sierra (10.12), up to Ventura (13), it stopped working in Sonoma and continues to fail in the same way in Sequoia (14 - 15). When I display the ruler, the contents of the text area disappears leaving just a pale grey background. When I make the ruler invisible again the text reappears.
No errors are reported (at compile or run time). I have tried adding refreshes of the text view in various places with no result. I have (for Sequoia) used Interface Builder to force the text view to use TextKit 1, also with no success. I’m at a loss as to how to proceed because I’m not getting any diagnostics, simply changed behaviour.
My app provides a programming IDE. It includes a program editor that uses line numbering code for an NSTextView from WWDC/Noodlesoft. The line numbers are shown in the ruler which is sometimes visible and sometimes not. When I display the ruler, I also set the main text to not editable but removing this setting does not appear to make any difference.
Any suggestions would be very wel
PLATFORM AND VERSION
macOS, Objective C
Development environment: Xcode Version 16.0 (16A242d) [and previously Xcode 15], macOS All releases of Sonoma and Sequoia 15.0.1 (24A348)
Run-time configuration: macOS Sequoia 15.0.1 (24A348)
The sequence is essentially:
[editTextView setEditable:NO];
[self showRulerIn:editTextView visible:YES];
Using:
-(void)showRulerIn:(NSTextView*)editorTv visible:(BOOL)vis {
NSScrollView *scrollV = [editorTv enclosingScrollView];
NSClipView *clipV = [scrollV contentView];
MBEditorTextView *textView = (MBEditorTextView*)[scrollV documentView]; // The actual text
[scrollV setRulersVisible:vis]; // Creates the ruler if necessary
…
return; }
LINE NUMBERING CODE
The line number code comes from 2 sources but they are so similar that one must be derived from the other:
Apple’s WWDC 2010 code at: https://download.developer.apple.com/videos/wwdc_2010__hd/session_114__advanced_cocoa_text_tips_and_tricks.mov
Noodlesoft's code at: https://www.noodlesoft.com/blog/2008/10/05/displaying-line-numbers-with-nstextview/