Note that there are some explanatory texts on larger screens.

plurals
  1. POLine management in a text editor
    primarykey
    data
    text
    <p>I've been working on a text editor for some time. I made a custom edit control, from scratch, and I've got the basics down now. The problem I am facing is regarding line management. Since, my program relies on dividing the input text into lines(the text is printed line by line), line management is pretty important. I was using std::vector to store the line positions. I am using a Piece Table for my text processing, but for the sake of simplicity, let's say that I have an array of characters. I add/insert an element into the line vector every time the user presses enter. The issue is that every time the user inserts a character, the whole structure is disturbed. For example : </p> <pre><code> 0 1 2 3 4 5 6 7 8 9 10 text = ['h','e','l','l','o','\n','W','o','r','l','d'] state of line vector : line[0] = 0 line[1] = 6 </code></pre> <p>Let's say the user inserts a character('x') after the text[2]:</p> <pre><code> 0 1 2 3 4 5 6 7 8 9 10 11 text = ['h','e','l','x','l','o','\n','W','o','r','l','d'] state of line vector : line[0] = 0 line[1] = 6 </code></pre> <p>Because of the insertion, I would need to update the value of each element in the lines vector after the current line. The same for deletion. If there are 1000 lines in a program and the user edits the first line, it would be quite inefficient to update all 999 elements(except the first one). </p> <p>What I was thinking of was to keep each line independent of each other. But that would lead to complications when an existing line is divided into two lines. So I'd like to know what's a good way to go about the problem?</p> <p>Edit: Just to clarify, I am using a data structure called Piece Table. I am not using an array of characters. Here is what a piece table data structure is : <a href="http://www.cs.unm.edu/~crowley/papers/sds.pdf" rel="nofollow">http://www.cs.unm.edu/~crowley/papers/sds.pdf</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload