headbase-app / headbase

The customizable database for your brain. Note-taking, task-management, personal knowledge bases and more.
https://headbase.app
GNU Affero General Public License v3.0
1 stars 0 forks source link

Add better Automerge text editing support #20

Closed ben-ryder closed 9 months ago

ben-ryder commented 11 months ago

Right now I just do doc.text = newText when doing content updates, but this isn't good for supporting offline/concurrent edits as it just replaces all the text.

I'm thinking that I could use https://www.npmjs.com/package/diff to compare the old and new string values when an edit is made and then use A.splice to apply each change. I think this would involve migrating to the Next API too:

Doing it this way would allow me to continue using the basic codemirror setup I've got with value and onChange using a basic string type. I could also then contain this functionality within the state actions, and the frontend can be simple as it can just pass the full updated text. This diff processing could be done once on save, and/or on some sort of debounce'd autosave which can automatically save changes after x seconds of inactivity. I think this will work ok for me here because my use case is not real-time collaborative sync, but is single user cross-device sync with offline support.