Skip to content

Cannot prevent UndoRedo from storing state on Translate event with no actual movement #1149

@aleupons

Description

@aleupons

Hello, I have encountered the following issue using the Transform and UndoRedo classes from the library:

OpenLayers triggers the interaction Translate events when a feature is selected even if we just click on the feature itself and it does not move. To prevent this, since in the captured "translateend" event we do not have, as we do in native OL, the "e.startCoordinate" or "e.coordinate" properties, I had to store all "e.features" coordinates during "translatestart" and compare them at "translateend". This workaround works, but I am not sure if it is the best solution.

The real problem comes when trying to prevent this "phantom change" from also adding a new state to UndoRedo, but it seems impossible. Somehow, an internal change event is triggered automatically and this new false state is added to the stack, and it is impossible to prevent or undo it: using "setActive(false)" the state is still added (as if something is called before "translatestart"), if we programmatically force an "undo()" a later state will be pushed to the redo stack, and if we use "shift()" only the first undo state is ever removed. This means that if this "phantom change" occurs at any other point in the flow than the first change, the solution will be incorrect.

I think it would be useful to be able to manually disable the creation of new states in UndoRedo, or at least to be able to call a function similar to "shift()" but that deletes the last state and not the first.

You can see this behavior in all examples of the UndoRedo class: https://viglino.github.io/ol-ext/examples/interaction/map.interaction.undoredo.html

Thank you very much

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions