FormidableLabs / use-editable

A small React hook to turn elements into fully renderable & editable content surfaces, like code editors, using contenteditable (and magic)
MIT License
483 stars 13 forks source link

Feature Request: Select All #12

Open ergodic1 opened 3 years ago

ergodic1 commented 3 years ago

Thanks for the great library.

Is it possible to expose selectall functionality? I can achieve this by using the following on click, but it seems like programmatic control over range selections is possible with the library.

document.execCommand("selectAll", false, undefined);

Something like Edit.select(range)?

kitten commented 3 years ago

I'm a little hesitant to include this. The logic exists but you have found a valid way to select all content natively without any quirks that need to be smoothed over.

In general, I'm struggling to find use-cases for selecting a specific range beyond selecting everything, which is easily possible. I think selecting a specific range may not be a common use-case. I can be convinced otherwise, but currently I'm on the fence on implementing this 😅

ergodic1 commented 3 years ago

The reason select all might want to be included is that while the above "works", it's a little buggy in terms of UX and I'm not sure we could rely on it to work in a production setting. The execcommand's success relies on the field being the currently focused field, and if there are other ui updates scheduled (popups etc, other events) then I've noticed just in dev mode it's behavior isn't reliable.

zane commented 2 years ago

I also have a need for this, and am reluctant to use document.execCommand because it's deprecated.