News for hackers. Stuff that matters.
Re:Show HN: Replay your typing in a few lines of JavaScript by sonofhans on Friday March 01, 2024 @02:00PM (#39565407)
This is nice.

I’m curious — it looks like you’re storing the full text string along with the timestamp. At first I thought you were capturing keystrokes, but it makes more sense to capture the full text, so you can allow people to edit with mouse/arrow keys, etc.

It will fall over at some point though, right? If you work on this more, is the next logical step to store a diff with each timestamp, rather than the full string?

Re:Show HN: Replay your typing in a few lines of JavaScript by seafoamteal on Friday March 01, 2024 @05:53PM (#39567790)
That's what I was thinking as well. I loved the demo, but was a bit surprised at how much redundant data was stored behind the scenes.

Capturing keystrokes could still be a viable option if you maintained something like a virtual cursor that could move around the text display area.

Or of course, diffs are the most straightforward way to do it.

Re:Show HN: Replay your typing in a few lines of JavaScript by Einenlum on Friday March 01, 2024 @06:53PM (#39568291)
Thanks, this is an interesting point. Storing the full message indeed has a downside in terms of storage (but for a short text it should be unnoticeable). I guess it also brings something positive: you can select the whole text, delete it, and start again, and the whole action should be stored. Making a diff to represent this is way more complicated.

I'll still think about this though. I think I could find a way to reduce the data size for most use cases.

Re:Show HN: Replay your typing in a few lines of JavaScript by a-r-t on Friday March 01, 2024 @07:50PM (#39568739)
You can introduce multiple types of changes, for example: addition at the end, removal of N characters from the end, and complete string replacement, etc. Then for each change you can calculate which type is more efficient to store.
Re:Show HN: Replay your typing in a few lines of JavaScript by Einenlum on Friday March 01, 2024 @08:06PM (#39568832)
Yes, already working on it! Thanks!
Re:Show HN: Replay your typing in a few lines of JavaScript by Einenlum on Saturday March 02, 2024 @04:44AM (#39571365)
I changed the code to add a diff. Thanks for your input! (pun intended)
Re:Show HN: Replay your typing in a few lines of JavaScript by sonofhans on Saturday March 02, 2024 @12:45PM (#39574201)
That was quick! It seems to work as well as ever. The data structure is less legible, but a lot more efficient.

Such a little project. I hope to find a use for it.