James Edwards on Nostr: Writing #javascript to handle #caret browsing is interesting. Since `keydown` only ...
Writing #javascript to handle #caret browsing is interesting.
Since `keydown` only fires for targets that can be `activeElement`, the event target from caret navigating plain text is always <body>.
However you can identify which element contains the caret, by evaluating the range data, which you can also do from `selectionchange` events.
And get this -- Safari still fires those events, even though it doesn't support caret browsing ... because it actually does, it just doesn't show the caret!
Published at
2024-05-16 18:40:00Event JSON
{
"id": "2668708393b0041ead4d9986a20a47ce3145d08481295e82ea4411234c5ea4d5",
"pubkey": "5d78a900466c87ad276db31284220f3ac3611f9d40d4e0f9adabe87673b35e0a",
"created_at": 1715884800,
"kind": 1,
"tags": [
[
"t",
"caret"
],
[
"t",
"javascript"
],
[
"proxy",
"https://mastodon.world/users/siblingpastry/statuses/112452226305675941",
"activitypub"
]
],
"content": "Writing #javascript to handle #caret browsing is interesting.\n\nSince `keydown` only fires for targets that can be `activeElement`, the event target from caret navigating plain text is always \u003cbody\u003e.\n\nHowever you can identify which element contains the caret, by evaluating the range data, which you can also do from `selectionchange` events.\n\nAnd get this -- Safari still fires those events, even though it doesn't support caret browsing ... because it actually does, it just doesn't show the caret!",
"sig": "9460e3dbb743a9fd62abef952fbb8d52283e256d8af91a561b1f79babe6ebbe950c7a2f47c4e30bb0ba06b0bbbcff3e3f3174cc44286987c598e636ba7e2df42"
}