Re: Crash in dragImageForSelection


John Brownie
 

Gary L. Wade wrote on 27/4/19 02:07:
The bug in documentation has been reported.

Try forcing layout on the text view after setting the selection; there might be some kind of delay from setting it till it’s renderable, and that might get it refreshed.
Doesn't seem to help.
On Apr 26, 2019, at 11:51 AM, Ben Kennedy <ben-groups@...> wrote:


First of all, you're treating textView as an optional sometimes, and force-unwrapping it elsewhere. Prefacing the whole block with a `guard` or `if let` would clean this up.
Yes, it's a result of various ways of setting the range correctly. I've fixed it so it looks nicer.
More on topic, I looked up the documentation for `setSelectedRange()`, and it is strange:

https://developer.apple.com/documentation/appkit/nstextview/1449256-setselectedrange?language=objc

charRange: A non-nil, non-empty array of objects responding to the NSValue rangeValue method. The ranges in the ranges array must begin and end on glyph boundaries and not split base glyphs and their nonspacing marks.
The method clearly takes an NSRange argument, but the documentation instead talks about an array of NSValue objects. WTH? I guess this is a documentation error? (Somebody file a radar... crickets)

If you call `selectedRange` immediately after `setSelectionRange(…)`, does it reflect the range you tried to set?
Yes, the range is correct after calling setSelectedRange.

I wonder if the answer is to draw my own drag image...

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.