-
Notifications
You must be signed in to change notification settings - Fork 418
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
Command stack change event should be more detailed. #479
Comments
Can you please share a use case where such extended context would be required? |
Going back to my previous statement about environments, it's already very useful. Take for instance a case were I want to perform an undo. Editors have dirty states when compared to the version saved on disk. After one edit, an undo should restore the diagram to the same as the one saved on disk and the diagram shouldn't be considered dirty anymore. Arguably an important feature to implement when integrating with a environment. Without this context, only knowing something changed, the only solution would be to compare the diagram with the saved one on each change. Afaik updating the dirty state directly is not supported by any APIs, so you'd have to hack it together by simulating changes and undos. It's possible to invoke undo() and redo() manually, so by listening for the environment's own events and disabling them on the editor, you could do the same thing, but these two functions also emit a changed event, so I'd have to ignore one, but that would be unstable without knowing the context of each one. Adding the stack to the context as well is related to issue #478 as that enables other useful editor features like backups or concurrent editors for the same diagram. |
Please have a look at this sandbox: https://codesandbox.io/s/4fh3c?file=/app/index.html You can actually listen to |
Thank you! Your suggestion really put the idea into a different light. It appears to solve a lot of issues. However the case where I would make a change, save, undo, then redo to restore saved state is problematic though. I would still need to tell the difference between a redo and a regular action to know if the current state is dirty. Either way, trying to indicate to an editor environment that an undo/redo has happened is unintended usage. They have their own "commandStack" and send the difference/changes to the editor which executes it. In vscode it would work like so: I want to add that upon further consideration, including the executed/reverted commands in the context isn't required at all for this use case. It is related to my other issue, but without being serializable is basically pointless. Either way, how it is polled is irrelevant for this issue. I pointed out that I had some difficulty with my PR, but if I remove that part, I can make it ready to merge. Fairly quickly assuming I did it right. |
The commands together with pre-/post-/etc. hooks are considered atomical in that sense that we don't allow user to undo in between. Given what I referred to in #479 (comment), can you please specify your feature request? Or maybe it's already implemented? |
I'm talking about the sync between the editor host and the webview (diagram). They can be in disagreement on if the redo or edit happened first without breaking the atomic paradigm. The issue is to the host, the redo event and regular new action event look identical. Specifically the feature is this: This is already implemented in the PR. The detail I want to retract from my request was this: This is also in the PR, thought not fully functional, but I shall remove it. |
Is this feature request accepted? The backlog label is added and the PR is fully functional, so I would assume so, but the PR is still closed as you were figuring out what you want to have. I described what the feature is in the above comment and it's exactly what was implemented in the PR:
|
I appreciate your persistence on this one. I also have to admit, that I did not fully understand why you need that feature. I've built a few desktop like apps around diagram-js based editors and did not see the use-case for more detailed events yet. A trick I employed is to checkout the command stacks Combining that knowledge with the last saved diagram, i.e. remembering To move this issue forward (and increase a likelyhood of the related PR being merged), maybe you can provide us with a simple mock up (i.e. codesandbox) that shows how you plan to accomplish your dirty check with the API update you propose. Correction: |
This is the specific problem I am trying to solve. I need to distinguish a do from a redo. This is impossible to do 100% reliably with the method you proposed. I made a codesandbox here to show why I want to distinguish these. Notice the You might be asking why I want this kind of setup. Why not just leave it up to the webview to undo and redo, then just inform the editor of this change? It's a simple answer, the vscode API does not support it. Specifically disabling the undo and redo keybindings in the editor isn't supported (since I need to replace them). The solution to the lack of information about a new action (whether it was a redo) is that the editor could try to deduce the missing information by predicting the incoming events. Basically the editor goes "I did a redo, so I can expect the next commandStack event to be a redo". The critical bug is a possible desync conflict between the webview and the editor. With this solution implemented, try making a change and then quickly hitting the redo button. Now the editor will expect a redo event, but it was actually a new action. No more events will occur because the redo action will not have anything to redo. Now you will have an incorrect dirty state and a desynced edit stack. Now notice how simple the solution becomes with my proposed change in the function If this is still unclear, please do say so and I can try to implement the proposed "solution" I claim contains a bug and demonstrate it. If you can solve this issue with the setup in the codesandbox without desync issues, then you're definitely smarter than I am and I would appreciate it massively! |
Thanks for the sandbox. I'll have a look later this week. |
Can we get this issue resolved soon? I don't mean to be rude, but I don't want to maintain my own version of diagram-js forever |
Sorry for not being able to follow up with this one earlier. We'll look into this issue, eventually. |
I looked into your code sandbox and understood, more or less, what is going on. Sure, we could add a What I do not understand yet is this:
What do you mean by the vscode API does not support it? We did implement a couple of undo/redo capable editors on top of diagram-js/bpmn-js, but not on top of VSCode I believe. |
https://code.visualstudio.com/api/references/vscode-api#CustomEditorProvider Specifically
So I need to trigger this whenever
The extension is responsible for instantiating the VSCode host will trigger the VSCode considers a What I'm referring to is by hooking into the hotkeys in diagram-js, I could, for example, send a Will you point me to the editors you say you implemented? I would like to take a look |
Hooking into any kind of "keyboard shortcut" on the diagram-js level does not sound like a proper approach to hook into VSCode. Embedded into VSCode, VSCode should likely be fully in charge of managing keyboard shortcuts, including undo and redo. We offer an abstraction, If I understand your answer correctly, #479 (comment) is everything you need? Specifically:
It allows you to generate these edit events only on DO or CLEAR but never on undo and redo, as these are managed by VSCode. |
I don't quite understand how this solves my issue. I assume you are referring to this, but commandStack doesn't use it to execute, and calling Could you please elaborate? |
Let's complete one thread after the other. Would #479 (comment) solve your issue? With #479 (comment), part one I was merely suggesting a good practice, embedding our library into an external editor. |
Ah sorry, I missunderstood
Yes, correct |
Great 🎉, 🥳. Would you like to contribute the described solution, i.e. every |
Updated the issue description, according to the solution we found, both understood, and acknowledged. Thanks for your patience, and your insights into your use-case. |
Happy to! |
Closed via #529. |
Is your feature request related to a problem? Please describe.
Using the modeler in an environment with it's own implementation of editor features can be quite frustrating. There is no convenient way to tell what the commandStack did, only that it did something unknown. An example of such an environment is VS Code or atom. Such an environment needs context to function correctly.
Describe the solution you'd like
The commandStack should emit more detailed events, likecommandStack.pushed
,commandStack.undid
&commandStack.redid
. Or it could just be added as event data to thecommandStack.changed
event. Additionally, the executed/reverted commands in that logical unit and their context should be included.Every
commandStack.changed
event has an additional propertytrigger
that is eitherundo
,redo
,execute
orclear
. This allows integrators to distinguish the different change events, i.e. to manage dirty state externally.Describe alternatives you've considered
Overwriting the commandStack module is also an approach I could look into, but plugins shouldn't change core functionality due to compatibility issues. However other than that it would be a very reasonable approach.
I could use the
commandStack.execute
event and a timer to aggregate all commands with the same id, but it would be great to be able to undo immediately, not after timer.I could just check the internal data of the commandStack module to determine what exactly changed, but this is unreasonable considering I would be practically implementing my own commandstack in the process, just way more hacky.
The text was updated successfully, but these errors were encountered: