When I double tap on an image url when using Safari, the selected text includes the extension only if the filename is lower case. Why?
I write a lot of SE questions and when I include multiple images I frequently copy/paste just the names.
I've just started using Safari on my new MacBook after using Chrome on my old MacBook, and I've discovered that when I double-tap to select the text it sometimes grabs the .jpg
extension and sometimes doesn't. As far as I can tell this depends on whether the imgur filename begins with an upper case or a lower case letter.
Is there any way I can get this selection behavior to be case-agnostic?
With chrome the selection always stops before the period, but Safari seems to be more "creative" in where the selection ends.
Try it yourself!
i.stack.imgur.com/GESmi.png
i.stack.imgur.com/124RA.png
i.stack.imgur.com/eFGbq.jpg
i.stack.imgur.com/JOKd4.jpg double tapping only selects "JOKd4" and not ".jpg"
i.stack.imgur.com/amD8b.jpg
i.stack.imgur.com/wbP9b.jpg
i.stack.imgur.com/bidkm.jpg
i.stack.imgur.com/bebR8.jpg
Solution 1:
This is a quirk of the UAX #29 standard on Unicode word segmentation boundaries. Basically, this document specifies standard rules for determining what's a "word" in a string of Unicode text. Cocoa Text (the macOS text subsystem) conforms to these rules when implementing features like "double click to select a word".
Using uniseg, a Python library that implements these rules, we can see the word boundaries for these two strings:
In [1]: list(uniseg.wordbreak.words("JOKd4.jpg"))
Out[1]: ['JOKd4', '.', 'jpg']
In [2]: list(uniseg.wordbreak.words("eFGbq.jpg"))
Out[2]: ['eFGbq.jpg']
In the first case, UAX #29 rules specify there are three words in the text (which you can check by trying to double-tap select each piece one by one). In the second case, it specifies there is only one word.
This should be standard behavior across Cocoa apps, but overridable by individual apps if they care to. Chrome, presumably, implements an override for text / word selection behavior beyond the Cocoa default. I'm not sure if there is a way for users to override this behavior without access to source code.