[Feature request] How to tell if historyStateChanged event is for new state?

My goal is to detect if there’s an active selection using notification listener. Initially I used set event and checked if that’s for (de)selection, but I figured I also need to check history state if user changes - I should also detect if there’s an active selection. So on historyStateChanged I get doc selection property and see if there’s one or not.

The problem is, I can’t see how to identify if history state is new, or user undid/redid something. I wouldn’t want to call BP getting doc prop on every user action :confused:

So if there’s no way to know if state is new, that would be a feature request for the event - please add a boolean flag like newState or similar. Or at least total states count maybe, so that we were able to compare with itemIndex :thinking:

There’s a count property, which should be the total count of history steps.
Also, history states have an ID so you could remember the highest ID and if you listen to a historyStateChanged event whose ID isn’t higher than that, it has been an undo.

At least I didn’t see this in Alchemist listener result. Would’ve definitely used that. Will recheck later :confused:

The approach with keeping ID in memory, isn’t what I’d like to do, because it also would require getting highest IDs of all open documents (and saving them; and updating them) on plugin load, but will consider

So I checked and count isn’t there :confused:
But now I figured that count wouldn’t help anyway, because on the last state there would still be no way to know if it’s a new state or just a Redo. Implementing the suggested saved IDs for each open document seems like overkill :frowning:

I’ll leave for now BP calls and see how it goes while testing, but a flag would be a proper solution IMO

You should also take snapshots into consideration. And possibility to manually remove history states. Also you can set number of history states down to 1. Then you can also have linear and non-linear history so ID numbers of history steps might not have only incremental order. But each history ID should be unique within PS session. Also you can have multiple documents so you need to keep track in which document event happened.

1 Like

I think I’ve got it all covered with 3 events:

  • historyStateChanged (self explanatory)
  • layersFiltered (trigers whenever active document changes)
  • modalJavaScriptScopeExit (trigers when some plugin changes state)

On all 3 I still check documents selection property :thinking:
historyStateChanged is not triggered when other two happen.

BTW, any info what exactly layersFiltered is?