Skip to content

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

Merged
merged 21 commits into from
Apr 23, 2024
Merged

Follow-up PR for cancellation of transactions #3254

merged 21 commits into from
Apr 23, 2024

Conversation

amolenaar
Copy link
Member

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

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.

@github-actions github-actions bot added the python Pull requests that update Python code label Apr 17, 2024
@amolenaar amolenaar force-pushed the 0lione-main branch 2 times, most recently from c7ed01e to bdce275 Compare April 17, 2024 13:01
@0lione
Copy link
Contributor

0lione commented Apr 17, 2024

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()

@amolenaar
Copy link
Member Author

Thanks for testing 🙏 . I'll try to reproduce it.

@0lione
Copy link
Contributor

0lione commented Apr 17, 2024

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.

@amolenaar
Copy link
Member Author

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 on_drag_end is doing anything out of the ordinary.

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 end signals. It may be that we need to prevent controllers from being swapped out when in a transaction.

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.

@amolenaar
Copy link
Member Author

I created a new diagram with 2 classes, connected by an association.
Now move one end of the association, and hit the right mouse button while dragging.
Gaphor will not react to click events anymore.

@amolenaar
Copy link
Member Author

amolenaar commented Apr 19, 2024

@0lione I cannot reproduce the issue you describe with tool.reset().

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.
@amolenaar
Copy link
Member Author

I added more updates, mostly on undo management:

  • Consolidate undo/redo stack handling. Basically 4 things can happen:
    1. A transaction has to be added to the undo stack (clear redo stack).
    2. A transaction is undone: remove from undo stack and add to redo stack.
    3. A transaction is redone: remove from redo stack and add to undo stack.
    4. A transaction is rolled back: do not change the undo and redo stack.
  • Add a second phase for transaction rollback events, similar to commit events
  • Remove the workaround to allow for certain events to happen outside a transaction. Since diagrams are now completely updated in a transaction, there's no need for this.
  • Documentation updates

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.
@amolenaar
Copy link
Member Author

@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.

@amolenaar amolenaar requested a review from danyeaw April 21, 2024 14:31
@danyeaw danyeaw added bug An issue in the application and removed python Pull requests that update Python code documentation labels Apr 23, 2024
Copy link
Member

@danyeaw danyeaw left a 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!

@danyeaw danyeaw merged commit ba76abb into main Apr 23, 2024
@danyeaw danyeaw deleted the 0lione-main branch April 23, 2024 01:33
@amolenaar
Copy link
Member Author

@0lione Thanks again for helping out. You're changes helped uncover some deeper issues in the undo functionality.

@all-contributors Add @0lione for code.

Copy link
Contributor

@amolenaar

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

I've put up a pull request to add @0lione! 🎉

@0lione
Copy link
Contributor

0lione commented Apr 26, 2024

@0lione Thanks again for helping out. You're changes helped uncover some deeper issues in the undo functionality.

@all-contributors Add @0lione for code.

Thanks it was a pleasure to contribute in this amazing project.

Copy link
Contributor

@0lione

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

@0lione already contributed before to code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue in the application
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants