Detecting deleted lines in a QTextDocument

  • I have a mapping in my application that must be maintained for every line.
    When the user deletes a line, I'm trying to detect which line so I can update my mapping.

    The contentsChange signal has where in the document a change occurred and how many characters are added or deleted, but at this point it's too late to determine what was there before the delete.

    I've been thinking of a few possible ways to get the information:

    1. If I peek at the undo stack maybe I can get at the lines that were deleted, but this may not be reliably for large change blocks.
    2. I could keep a previous state of the file for every change, and then try to look there when the signal is raised. This seems like a lot of unnecessary overhead.
    3. Maybe I need to dig into the source and create a new signal before something is about to be deleted.
    4. I put some more userState or userData in every block that map to my array, and if I notice missing consecutive blocks indices, I can infer the deleted blocks, update my mapping, and then update all of the remaining blocks in the file with new consecutive indices.

    What's the most graceful (simplest and inexpensive) way to do this?

Log in to reply