GraphiteEditor / Graphite

2D vector & raster editor that melds traditional layers & tools with a modern node-based, non-destructive, procedural workflow.
https://graphite.rs
Apache License 2.0
7.31k stars 387 forks source link

Make the Fill tool's fill click operation cancellable #1666

Closed milan-sedivy closed 3 months ago

milan-sedivy commented 3 months ago

This is the last tool that needed a cancellable transaction.

It is implemented in a way that it introduces a "Fake drag" the reason for this is simple, emitting DocumentMessage::AbortTransaction currently works as an undo step. Thus if the user would not perform an operation before trying to cancel the transaction it would result in undoing his current history.

This could and should be reimplemented once a Document can be in different states such as "Transaction In Progress"

Closes #1657

github-actions[bot] commented 3 months ago
📦 Build Complete for 3053c3a6bffe887905ebe4b2aeaf78400e3880b5
https://24122b30.graphite.pages.dev
milan-sedivy commented 3 months ago

There are a few bugs I found:

  • If I click and drag outside the shape then release, I get stuck in the mousedown state (notice the hints bar) and neither left clicking nor right clicking nor Escape outside the shape fix the stuck state (I have to left click to apply, or right click to abort, inside the shape)
  • If I hold down the left mouse button, then hit CtrlZ, then abort with Rmb, this causes it to go back to a previous history step (it undoes the creation of a layer I made immediately before this, for example). If this is true for all the abortable/cancellable tools you've worked on, let's skip fixing it in this specific PR.

The CTRL+Z+ESC/RMB will probably be true for all tools but I will look into an easy hotfix (before the whole transaction system is refactored so that it doesn't rely on undos).

As for the other behavior I will check and see what I can do to fix it.

milan-sedivy commented 3 months ago

I noticed a new TODO (or maybe old?) i.e.

// TODO: Use a match statement here instead of if-else

In that given case i think it's preferable to keep it as an if-else rather than match, because of the fact that match would just add another arm and I think that down the line it might lead to uncaught issues.

milan-sedivy commented 3 months ago

@Keavon

  • If I hold down the left mouse button, then hit CtrlZ, then abort with Rmb, this causes it to go back to a previous history step (it undoes the creation of a layer I made immediately before this, for example). If this is true for all the abortable/cancellable tools you've worked on, let's skip fixing it in this specific PR.

As suspected this is something that is affecting all tools that either call Undo or AbortTransaction. (Not just the tool I worked on)

I was hoping for a quick hotfix through a "hack" in default_mapping.rs but unfortunately to implement the hack I would have to refactor that file. This definitely needs a separate issue/PR So currently there are two approaches I suggest:

Keavon commented 3 months ago

Ok, thanks for investigating. Can you move your findings about the undo bug to another issue which can be home for that future PR?

The to-do I added is a suggestion to better model the invariants. Else doesn't imply filling with the secondary color. If there's something other than filling with primary or secondary color, it'll still enter the else arm. A match statement better models the problem and is this cleaner.

milan-sedivy commented 3 months ago

Ok, thanks for investigating. Can you move your findings about the undo bug to another issue which can be home for that future PR?

The to-do I added is a suggestion to better model the invariants. Else doesn't imply filling with the secondary color. If there's something other than filling with primary or secondary color, it'll still enter the else arm. A match statement better models the problem and is this cleaner.

Hmm good point didn't think about that.

As of the PR it's already done (with an issue)

Keavon commented 3 months ago

!build

github-actions[bot] commented 3 months ago
📦 Build Complete for e85f99f937ae7223e0bbf0bd47a74485d913dae1
https://a9db192f.graphite.pages.dev