fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.25k stars 116 forks source link

GhostText protocol wishlist #255

Open fregante opened 1 year ago

fregante commented 1 year ago

Current

Future

  1. Just connect to WebSocket, no intermediary HTTP server
    • alternatively, just use EventSource and HTTP/2 instead of WebSocket
  2. Add timestamp to messages in order to discard messages that are out of order
  3. Send the full URL on connection so that the editor can use the filename and/or set the syntax
  4. the text selection can be sent separately from the content
  5. the editor should not send the syntax back
  6. send editor description/title/label (via label, [title], [aria-label], etc) to be used as tab title
subnut commented 1 year ago

My suggestion?

Implement diff mode.

First connection

Browser sends editor the metadata (title, url, etc.) and the full text

Rest of the lifetime

Every time text changes in either browser or editor, it sends out a message that contains the line numbers from which the change starts, and the line number at which the change stops, and the whole text between those line numbers.

e.g.

This way, GhostText can work on big files without needing to consume a ton of CPU.

fregante commented 1 year ago

Implement diff mode.

heh I was thinking about that earlier, but that complicates things a lot, because suddenly every message has to be delivered.

The other complication is that a diff algorithm, especially with multiple cursors, still doesn't come free (CPU), and has to be implemented by each editor plugin in different languages. One editor gets this wrong and people lose data and open issues here.

The only way I could do this would be with a standard, simple diffing algorithm available in multiple languages. This would avoid implementation errors and waste of dev time. I'd probably not implement this myself in any case due to the complexity, compared to just dynamic throttling (see the "updates" section in https://github.com/fregante/GhostText/issues/256)

Browser sends editor the metadata (title, url, etc.) and the full text

Totally agree, the current setup is awkward. PR welcome for that (including protocol.md). I suppose it would need to be sent via URL parameter though, which means it's limited in length (32k) and therefore it would need to be skipped when too long.

I'm happy to make changes that are backwards compatible, I already made a couple of improvements this week: https://github.com/fregante/GhostText/commits/main/PROTOCOL.md