Go Ahead, Undo That Typo


It’s finally here! It is now possible to undo and redo while editing a note.

Whoo!

Beyond that, I’ve fixed a few (mostly minor) bugs.

Undo

I am thrilled to push this update. Not being able to easily undo a mistake is annoying at best and life ruining at worst.

It should work™ without any issues but I just finished up this feature and it was kind of a pain to get working so I expect to find something that’ll break.

The base undo system is fairly straight forward. It starts with the raw string data and either appends or deletes text at a position relative to the beginning of the string.

Each new edit is pushed onto a stack which can be popped off to undo that change. Redoing is as simple as moving the stack pointer back to the data that was previously popped.

The real tricky part was making sure my edit system and my undo system work properly together.

The Mistake of Rewriting

When I first approached the problem I though, “Well, this is a good time to just rewrite the editing system.”

Better sense prevailed and I decided to just retrofit my existing system knowing I could reuse my undo system in an update editing system. Otherwise, I’d still be working on it.

It was tricky though.

You see? When I originally wrote the note system, I more or less geared it towards how it’s seen rather than how it’s edited. Seeing as how most of the time spent in the program is showing the notes rather than editing them, it made sense.

However, that means when editing a note, it’s done on a line by line basis. Cross over into another line of text and now we’re having to work with two separate strings.

Which, by the way, made selecting multiple lines of text tricky so at least I’d already been here before.

I originally planned an elegant solution but instead chose brute force.

Planning Elegant Solutions

A warning about planning elegant solutions. They are guaranteed to contain many additional bugs over the brute force solution.

Sure, if the elegant solution presents itself, great! But that usually takes time to really get to know the problem by studying the brute force example.

At least, that’s been my experience.

Brute Force

On the other hand, brute force is a great way to shove a new feature down a program’s throat.

It’s not pleasant and it’s a mess to navigate, but the job gets done.

Luckily, I enjoy taking the time to clean up the code from time to time to pay off some technical debt.

It’s therapeutic and sometimes cool stuff happens.

Anyways, each time you append or delete, it takes the note data, converts it to a string and counts each line’s length to calculate the absolute position.

When you undo a change it edits the raw string and converts it back into note format.

It’s not super optimized but it works so for now I’m calling it.

One thing I might do in the future is to rearrange how I ferry the data through the update loop.

Put the stuff that needs to work on a raw string first, then convert it for stuff that needs to work in note format, which is then handed it off to the renderer.

Bugfixes

Only two bugs come to mind.

The first is a simple rendering bug that would display the edit cursor in arbitrary places. I wasn’t checking to make sure the cursor was within bounds and that mouse input would only be registered by the note when the mouse was over it.

There was an issue with my string parser that, when loading a link file, would strip off a newline character at the end of a note. That’s been fixed so hurray for less data corruption!

Other than that there were some minor fixes that should improve the programs stability.

At least a little.

What’s Next

With the editing undo system in place, I’ll be looking to refine the very basic global undo system. It’ll be very similar to the edit mode undo system, but instead deals with adding, removing, and moving notes around.

Still chasing bugs and all the coding I’ve done in the past week will need to be tended to as usual.

Otherwise, I have a few other features I’m tinkering with so I’ll have plenty of things to keep my occupied.

Files

LINK! version 0.6 — Forgotten Update 3 MB
Jul 30, 2021

Get LINK!

Leave a comment

Log in with itch.io to leave a comment.