Using a single std::string to store the contents of a document is a very naive design for a text editor. While it might be good enough for small documents, the problem is that the time most operations will take more timenow linearly scale with the longersize of the document is, so for large documents everything becomes very slow. A slightly less naive way to store the document would be to store the lines of the document in a std::vector<std::string>, as that at least makes navigation very quickfast, and edits within a line will also be quickfast (assuming you don't have extremely long lines). But there are data structures designed to make almost all operations fast, likeregardless of the number of lines or the length of the lines. Have a look at rope or aand gap bufferbuffers, although these are not the only ones.