mathuo / dockview

Zero dependency Docking Layout Manager. Supports Vanilla TypeScript, React and Vue.
https://dockview.dev
MIT License
614 stars 43 forks source link

Enhance onDidLayoutChange Behavior #520

Open sachnk opened 6 months ago

sachnk commented 6 months ago

Is your feature request related to a problem? Please describe. I'm using the onDidLayoutChange change from DockviewApi to detect changes in my layout so I can persist the layout to a database. When the onDidLayoutChange event is fired, I enable a button in my UI to save it. Otherwise, this button is hidden.

It looks like onDidLayoutChange gets fired even when the layout itself hasn't necessarily changed, but the active panel has. The result is that the user gets many spurious calls-to-action to save their layout, even though the only thing that's changed is which panel is currently active.

Is there a way to disambiguate a change in the panel that's currently active vs. an actual physical layout change, where a physical layout change would be a change in dimension, location, etc.

Describe the solution you'd like It would be great if there was a way to disambiguate the active panel changing vs. a physical layout change. Possible solutions:

  1. Pass a parameter to onDidLayoutChange that describes the nature of the layout change, i.e. a flag indicating whether it's just a active panel change, and/or dimension/location change, etc.

  2. Change the conditions of when onDidLayoutChange is fired to ignore active panel change, and add a new onDidActivePanelChange event for capturing changes in the active panel.

I think option (1) might be preferable because it maintains more backwards compatibility with the existing behavior.

Describe alternatives you've considered Couldn't find a suitable workaround. Maybe one exists and I've overlooked it?

Additional context None.

mathuo commented 6 months ago

In version 1.10.0 several enhanements have been make to the events dockview fires, reducing duplicate events substancially. You can find a good demo of that here https://dockview.dev/demo

In terms of active panel changes, the active panel is stored as a part of the layout object and is therefore changing an active panel will trigger a layoutChange event.

Could you checkout the latest version / demo and let me know what issues you may still see?

I will also take a look at flags for the layout events.