At the risk of an off-topic answer: You might consider looking into text editing data storage structures like a [piece table](https://en.wikipedia.org/wiki/Piece_table). It might make sense to store in a SQLite database, to some degree, and prevent you from needing to make large changes for small changes in text. There are of course other techniques around storing and managing documents for a text editor. They could very well all be overkill for your needs, just thought I'd throw one option out there.