FormidableLabs / use-editable

A small React hook to turn elements into fully renderable & editable content surfaces, like code editors, using contenteditable (and magic)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Select All

ergodic1 opened this issue · comments

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)?

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 😅

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.

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