Today I worked more on the text editor and I’ve concluded that I need to change its text system again. The problem is the current system doesn’t have any concept of lines until the text is drawn. Let’s look at how this plays out in a common situation: the user presses the up arrow key to move the cursor up to the previous line. The system doesn’t know the previous line’s length and it can’t move the cursor until it does. Its only option is to loop backwards through every character until it finds a line break, the beginning of the text, or it exceeds the maximum line length. Then it can move the cursor. If I had each line as a table, it could just look at the previous line’s length and move the cursor.
I didn’t want to use tables for lines because of line wrap. If the user has a line which wraps multiple times and then adds or deletes a character, I have to juggle the characters at the start and end of each line. Although, this seems like a small problem by comparison.
One thing which is mostly working is moving the cursor with the mouse. I just check when each letter is drawn whether the mouse click is within its bounding box, and if so, move the cursor.
Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.