Wednesday | 28 FEB 2024
[ previous ]
[ next ]

Formatting in EVA

Date: 2023-04-20

A semi-major issue in my editor was the format command. Formatting a file would clobber your history and you would lose the changes you did earlier. The way I dealt with this was to be very very careful when using the formatter and deciding to save. Saving would result in losing everything that happened before. This actually worked out relatively well, rarely did I regret saving after a format. However this was definitely a weak point for my editor.

I finally got around to implementing the undo/redo logic for formatting and I'm surprised at how simple it was. I must have made the problem much bigger in my head because this time around, it only needed a new event type. I keep track of the type of the event that happens before a change. Changing a character is a CHANGE type event, a delete is a DELETE type event and an insert is an insert type event. For each event, I save the line as it was. To add support for formatting, I simply added a FORMAT type event and saved the entire file.

This way when I hit the format event, I restore the entire file rather than a specific line. This worked beautifully and simply with my existing code and I'm pretty happy with how it turned out. This probably results in much larger file that contains the history but it's a small price to pay for being able to go through much more time. I can now get a proper replay of a file that I'm editing and it would be nice to make such a utility.