atlas-engineer / nyxt

Nyxt - the hacker's browser.
https://nyxt-browser.com/
9.77k stars 409 forks source link

Structural clipboard API/design #3426

Open kchanqvq opened 2 months ago

kchanqvq commented 2 months ago

Is your feature request related to a problem? Please describe. My immediate problem is that I'm writing a structural editor inside Nyxt and I find myself reinventing my own kill-ring to store DOM trees. It'd be better if I can use browser's clipboard-ring so that I can interoperate with other parts in the Nyxt eco-system.

Describe the solution you'd like Allow arbitrary data to live in clipboard-ring. Devise a protocol for interop (up to discussion).

Describe alternatives you've considered Serialize/deserialize everything into plain text and store into clipboard. However, this solution may encounter dilemma between descriptive but lossy encoding, or unreadable verbose text.

Edit: I just come up with another alternative, which is to always store a description string in clipboard-ring, and each application would maintain a hash-table from description string to actual objects. This require no change from existing code, but it might be more difficult to interop between different applications. We can discuss whether this alternative is desirable.

Additional context Many other computing environments have typed/structural clipboard, e.g. Apple: https://developer.apple.com/documentation/appkit/nspasteboard and W3C: https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/getType. We might get some inspiration from this.

The API design is still to be devised. Happy to discuss more, maybe on IRC (my username is qhong)!

aadcg commented 2 months ago

@kchanqvq I think you should focus on the problem that you're trying to solve (which is a Nyxt extension that implements a structural editor).

If you feel that part of that implementation should be at Nyxt's core, then we can certainly discuss it.