Discussion:
Typing with multiple selections in NSTextView
Georg Seifert
2018-09-19 07:13:53 UTC
Permalink
Hi

Is it possible to make NSTextView to allow typing with multiple insertion points? One can set multiple selection and delete all of them at once. But typing only replaces the first range and ignores the other ranges.

Thanks
Georg
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
Martin Wierschin
2018-09-19 16:26:26 UTC
Permalink
So far as I know this is not possible with a stock NSTextView. The selected range array is automatically normalized by NSTextView, to sort and coalesce ranges as needed. If any zero-length ranges are in a given selection array, only a single zero-length range is allowed and maintained by NSTextView. Any other zero-length ranges are discarded straight away.

Even if you override selection methods to coerce NSTextView to maintain multiple zero-length selections, I’d be leery about it doing the right thing when it comes to text insertion and other behaviors. I doubt it’s written with multiple zero-length selections in mind. At the very least you’d probably also need to override text insertion and insertion-point drawing, but who knows what other things you’d need to shore up.

If I were you and wanted to write this in the safest way possible, to ensure no unforeseen consequences, I’d probably subclass NSTextView to add a new property like “multipleInsertionPointIndexes”. Only your own code would need to interact with this property. Of course you’d still have to add NSTextView overrides to handle things and keep those indexes in sync, but this would ensure NSTextView’s code never sees multiple zero-length selections and never potentially enters unknown states.

Good luck!

~Martin Wierschin
Post by Georg Seifert
Hi
Is it possible to make NSTextView to allow typing with multiple insertion points? One can set multiple selection and delete all of them at once. But typing only replaces the first range and ignores the other ranges.
Thanks
Georg
_______________________________________________
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
https://lists.apple.com/mailman/options/cocoa-dev/martin%40nisus.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive
Georg Seifert
2018-09-20 06:54:48 UTC
Permalink
Thanks for the explanation.

I wonder why it supports multiple selection in the first place, when you can do almost nothing with it?

Georg
Post by Martin Wierschin
So far as I know this is not possible with a stock NSTextView. The selected range array is automatically normalized by NSTextView, to sort and coalesce ranges as needed. If any zero-length ranges are in a given selection array, only a single zero-length range is allowed and maintained by NSTextView. Any other zero-length ranges are discarded straight away.
Even if you override selection methods to coerce NSTextView to maintain multiple zero-length selections, I’d be leery about it doing the right thing when it comes to text insertion and other behaviors. I doubt it’s written with multiple zero-length selections in mind. At the very least you’d probably also need to override text insertion and insertion-point drawing, but who knows what other things you’d need to shore up.
If I were you and wanted to write this in the safest way possible, to ensure no unforeseen consequences, I’d probably subclass NSTextView to add a new property like “multipleInsertionPointIndexes”. Only your own code would need to interact with this property. Of course you’d still have to add NSTextView overrides to handle things and keep those indexes in sync, but this would ensure NSTextView’s code never sees multiple zero-length selections and never potentially enters unknown states.
Good luck!
~Martin Wierschin
Post by Georg Seifert
Hi
Is it possible to make NSTextView to allow typing with multiple insertion points? One can set multiple selection and delete all of them at once. But typing only replaces the first range and ignores the other ranges.
Thanks
Georg
_______________________________________________
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
https://lists.apple.com/mailman/options/cocoa-dev/martin%40nisus.com <https://lists.apple.com/mailman/options/cocoa-dev/martin%40nisus.com>
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net
Martin Wierschin
2018-09-20 15:35:03 UTC
Permalink
NSTextView's support for multiple selections isn't too bad. You can apply formatting to multiple selections out of the box, which is handy and probably the most obvious use case. Oh and you can copy multiple selections to the pasteboard all at once.

But I understand your frustration. It can be relatively tricky to enhance the text system in ways not originally conceived of by Apple. Still, NSTextView and friends are overall some nice tools.

Best,
~Martin Wierschin
Post by Georg Seifert
Thanks for the explanation.
I wonder why it supports multiple selection in the first place, when you can do almost nothing with it?
Georg
Post by Martin Wierschin
So far as I know this is not possible with a stock NSTextView. The selected range array is automatically normalized by NSTextView, to sort and coalesce ranges as needed. If any zero-length ranges are in a given selection array, only a single zero-length range is allowed and maintained by NSTextView. Any other zero-length ranges are discarded straight away.
Even if you override selection methods to coerce NSTextView to maintain multiple zero-length selections, I’d be leery about it doing the right thing when it comes to text insertion and other behaviors. I doubt it’s written with multiple zero-length selections in mind. At the very least you’d probably also need to override text insertion and insertion-point drawing, but who knows what other things you’d need to shore up.
If I were you and wanted to write this in the safest way possible, to ensure no unforeseen consequences, I’d probably subclass NSTextView to add a new property like “multipleInsertionPointIndexes”. Only your own code would need to interact with this property. Of course you’d still have to add NSTextView overrides to handle things and keep those indexes in sync, but this would ensure NSTextView’s code never sees multiple zero-length selections and never potentially enters unknown states.
Good luck!
~Martin Wierschin
Post by Georg Seifert
Hi
Is it possible to make NSTextView to allow typing with multiple insertion points? One can set multiple selection and delete all of them at once. But typing only replaces the first range and ignores the other ranges.
Thanks
Georg
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive
Uli Kusterer
2018-10-04 00:42:47 UTC
Permalink
Post by Georg Seifert
I wonder why it supports multiple selection in the first place, when you can do almost nothing with it?
The way I remember it being introduced at WWDC was not as "multiple selection" but rather as "column selection". That might make some of the oddities in the feature set a little more obvious: Extracting columnar data.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net

Loading...