PICO-8 Text Editor with Effects, #10

Today I worked on, you guessed it, word wrap. It may be so difficult because of how I’m storing the text. Early on, when I had one table to store the text, word wrap was almost automatic. I switched to multiple tables so that I could more easily move the cursor, but the downsides have proven to be much worse than I originally thought.

What I’ve learned so far is that the text has two states: its internal data structure and how it appears on the screen. The difference between the two is what determines the trade-offs. If the data structure is similar to how it appears on screen, some things are easy, like determining letters’ screen positions and moving the cursor between lines. But the trade-off is that word wrap is difficult.

In the preceding posts, I’ve talked about the data structures I’ve used for the text, and why I switched between them. What I’m finding now is that the editor still doesn’t have a strong enough concept of lines in its internal state. It squashes lines together when they should be separate. I either need to find some way to distinguish between word-wrapped lines or use a data structure which makes word wrap easy, like one table.

I did an experimental rewrite of the editor using one table to store the text and only doing word wrap at draw time. It’s already so much closer to functional than my main version. If I can get it working, not only will it solve my word wrap problem, but it will also support variable width characters.

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.