Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
4.8.5, 5.2.0
-
None
-
Mac OS X, PyQt4, Qt 4.8.5.
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.