Page 1 of 1

Cursor navigation in a text editor

Posted: Tue Jun 25, 2024 10:34 am
by hamith
I'm developing a text editor using esp32 to which an LCD display is connected. Currently, to edit a file, I have a single large buffer of characters which is displayed on the screen line by line. I have implemented line splitting so that a word doesn't break when it reaches the end of a line but shifts into next line. Now, how to handle cursor navigation such that when the user presses the left arrow key when the cursor is at the start of a line, the cursor should move to the end of the previous line, considering that the lines have different lengths and I don't know where the previous line ended?

I have tried to split the entire buffer into multiple buffers so that each buffer will take maximum of one line on the display. But while adding or removing characters to/from the buffer, it's really hard to keep track of all the buffers and update them dynamically.

allAboutCircuitsThreadPhoto.png
allAboutCircuitsThreadPhoto.png (10.4 KiB) Viewed 554 times

Re: Cursor navigation in a text editor

Posted: Sun Jun 30, 2024 2:56 pm
by RandomInternetGuy
This isn't really related to ESP32, but "large data buffer" for a text editor is headed down a bad path from the start.

Read up on the data structure known as 'ropes'. They're key to this class of problems.