Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-32689

QTextDocument Undo does not properly restore QTextCursor position in some cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 4.8.5, 5.2.0
    • GUI: Text handling
    • None
    • Mac OS X, PyQt4, Qt 4.8.5.
    • macOS

    Description

      Any number of QTextCursors may be associated with a QTextDocument. In my app I use these for metadata such as user bookmark positions and markers for other data. QTextDocument properly updates the position/anchor values of all cursors under most editing operations. However when an edit fully or partially overlaps the position/anchor of a cursor, the cursor is NOT properly restored by an Undo of that edit. Follow the directions displayed by the attached PyQt4 program to see the exact problem (should fail with Qt5 as well – the documentation is unchanged from 4.8 to 5.1).

      The fundamental problem is that QTextDocument seems to not record changes to associated cursors as part of each QUndoCommand. Instead it appears to rely on the natural effect of insert/delete actions to restore cursors to their original positions on Undo. This usually works EXCEPT in the case where the Undo insert/replace string spans the cursor position. Then the cursor's original position (and selection if any) is not properly restored.

      This causes my users to complain about incorrect bookmarks and other metadata, e.g. after they Undo a find/replace, a copy/paste, or the reflow of text margins.

      Attachments

        1. bookmarks.py
          3 kB
        2. bookmarks5.py
          3 kB
        3. myeditor.cpp
          2 kB
        4. myeditor.h
          0.2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            dcortesi David Cortesi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes