-
-
Notifications
You must be signed in to change notification settings - Fork 216
Follow-up PR for cancellation of transactions #3254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c7ed01e
to
bdce275
Compare
I haven't found the cause yet but in this solution if we complete a relationship and then move one of the handles and press any key we get an : "assert not self._current_transaction" when doing tx_data.commit() |
Thanks for testing 🙏 . I'll try to reproduce it. |
To continue on this issue I discovered that the problem is when doing tool.reset() to a drag. If we don't call the on_drag_end defined in gaphas in itemtool.py then we don't get the error. |
That's odd. It doesn't look like Something else occurred to me. If you change from normal item tool to a placement tool, all controllers on the view widget are removed and new ones are added. This could (partially) explain why the drag controller was missing It can also be that replacing controllers is a bad idea altogether. Instead we should add a limited set of controllers only once and change tool behavior from within those controllers. |
I created a new diagram with 2 classes, connected by an association. |
@0lione I cannot reproduce the issue you describe with I added an extra check so tools (event controllers) are not swapped while a transaction is active. Now right-click while dragging does no longer make gaphor unresponsive to mouse events. I noticed, though, that If I cancel a grag action, an entry is added to the undo stack. This should not happen. |
This is a touch one: at all times our transactions must be closed. When a key is pressed, the event sequence is broken and no proper finalization happens. Hence, transactions can remain open, which causes trouble if you want to undo changes. This commit fixes the case when a key is pressed. There may, however, be more cases that can cause inconsistency in the transaction stack.
This makes it a bit more clear what's happening. Also, rollback is now a 2 phase action.
We do not need to, since diagram updates and constraint solving now happen within the transaction anyway.
So that we do not add more and more transactions if 'end' handlers are not called.
I added more updates, mostly on undo management:
|
Often, when events are finally handled, the semaphore values for undo/redo/rollback have been reset already. Therefore we have to tell the transaction what "kind" it is: undo, redo, rollback, or a normal transaction (no context).
So it knows when a transaction originates from the undo manager, and therefore it's handlers should not run.
Transaction context is now provided on the transaction.
I think it's a sub-optimal solution, but undo manager *needs* to know what changed ASAP, so it can undo all those changes in case of a rollback.
The diagram should be up-to-date at this point, so we only need to render it.
@0lione @danyeaw Still I ended up having transactions for cancelled operation on the undo stack. This is because events are queued if they are fired from within an event handler. This is done to preserve the order of events. I changed tactics a bit and now set the transaction context (or intent). This allows me to differentiate between normal, undo, redo, and rollback transactions. I think the cancel/undo behavior is pretty stable now. More stable than it has ever been. It needs a round of thorough testing, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @amolenaar, these changes look great!
@0lione Thanks again for helping out. You're changes helped uncover some deeper issues in the undo functionality. @all-contributors Add @0lione for code. |
I couldn't determine any contributions to add, did you specify any contributions? I've put up a pull request to add @0lione! 🎉 |
Thanks it was a pleasure to contribute in this amazing project. |
I couldn't determine any contributions to add, did you specify any contributions? @0lione already contributed before to code |
PR Type
What kind of change does this PR introduce?
What is the current behavior?
You get inconsistent behavior (issues with undo) when you press a key while dragging.
Issue Number: #3209
What is the new behavior?
Tried to fix it by cancelling all transactional event sequences as soon as a key is pressed.
Other information
This is a follow-up on the great work @0lione started.