CodeDocument request: insertLine(string...)


#1

Would it be possible to add an insertLine(string...) method to CodeDocument? Would something like this work?

void CodeDocument::insertLine (const int lineIndex, String text) const noexcept
{
    const CodeDocumentLine* const line = text;
    lines.insert(lineIndex, line);
}

#2

Your code example wouldn't work (and isn't even legal C++!), but you can add a line easily enough anyway, e.g.

doc.insertText (CodeDocument::Position (doc, lineNum, 0), "new line\n")

 


#3

Thanks Jules, the C++ police are constantly after me, the fact that I'm a musician seems to throw them of the scent!

 

 


#4

smiley


#5

I'm afraid that this is not working as fast as I would have hoped. Up until this point I simply populated a string array with my text file, and then iterated through that, inserting lines where needed. I would then use StringArray::joinToString() and update the contents of my CodeEditorComponent. The joinToString method started to slow down when the number of strings in the array got quite large. I thought inserting the code directly into the editor would be better but calling CodeDocument::insertText() around 30 times in quick succession also slows down my application. It just hangs for a few seconds until the routine has finished. Is this expected when inserting lots of lines into a document? If so, is there a better and quicker way?


#6

Well inserting into the document isn't designed for speed - it involves maintaining an undo chain, updating listeners, etc etc.

I don't know exactly what you're doing, but joinIntoString is a pretty damned efficient function, so if that's not fast enough you might need to build your own special container that's optimised for your specific task.


#7

Thanks Jules, that's good to know. I've no doubt that I'm over complicating things here!