I have a app I have developed over last 17 years and I noticed an NSTextView field that I set up without word wrapping no longer scrolled in the horizontal direction. I turned off wrapping with a method from Apple documention (last updated 2019) with key code being
[[theTextView enclosingScrollView] setHasHorizontalScroller:YES];
[theTextView setHorizontallyResizable:YES];
[theTextView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[theTextView textContainer] setWidthTracksTextView:NO];
It adds horizontal scroll bars, makes text view resizable in horizontal direction, makes the text container very wide, and sets container to track text view width changes.
But in MacOS 10.12 (or newer, I was using 10.13), the text view no longer resizes horizontally and one cannot scroll long lines in the horizontal direction. After 3-4 hours of trying various thinks, I found this tidbit in NSTextView documentsion
In macOS 12 and later, if you explicitly call the layoutManager property on a text view or text container, the framework reverts to a compatibility mode that uses NSLayoutManager.
I was then able to restore word wrapping with scrolling by adding the line
NSLayoutManager *lm = [theTextView layoutManager]
This call was enough; no need to use the layout manager. My code now works again.
My problem is solved, but the solution raises the questions --- what is "incompatibility" mode if this line is not called? Do I have to find all my NSTextViews and insert this call otherwise things won't work in MacOS 10.12+? And finally, what are the benefits of using "incompatibility" mode, which seems to stop using NSLayoutManager, and how does one do layout in that mode? The brief developer documentation in XCode did not make that clear.