-
Notifications
You must be signed in to change notification settings - Fork 135
Description
Summary
I would like to propose the addition of an onDidSashChange event to the Dockview API. This event would allow developers to detect specifically when a user has finished dragging a sash to resize panels.
Motivation
The primary goal in my project is to "remember" user layout preferences (specifically panel size ratios). However, implementing this reliably with the current API has proven difficult due to several technical hurdles:
- Ambiguity of
onDidLayoutChange: This is the only event triggered when dragging sashes, but it triggers for both user interactions and system-level shifts. It’s nearly impossible to isolate intentional user-initiated sash drags from automatic reactive updates. - Precision Drift during Serialization: I've observed that even if the container size remains identical, the output of
toJSON()after afromJSON()call often contains minor discrepancies (a few pixels of drift). This makes "deep-comparing" JSON states a fragile strategy for detecting "meaningful" changes. - Host Resizing Interference: When the host container resizes,
toJSON()values change naturally. Differentiating these automatic adjustments from intentional user resizing is complex, and using aResizeObserveras a workaround introduces race conditions.
By combining a dedicated onDidSashChange with other explicit events (like onDidAddPanel, onDidMovePanel), we could implement a much more robust logic only when necessary.
My Experiments
I have attempted to fork the repository and implement this locally. While I managed to get it working for my specific needs, I used AI assistance to bridge my gaps in understanding the internal code structure. The resulting code is a "functional hack" that proves the feature's utility, but it likely doesn't meet the engineering standards or architectural patterns of this library. Therefore, I haven't opened a PR as the code would need a more proper implementation.
Expected Behavior
A clean, native event emitter that signals the end of a sash drag interaction:
// Example usage
api.onDidSashChange(() => {
saveLayoutToLocalStorage(api.toJSON());
});Final Thoughts
I believe this addition would be highly beneficial for anyone looking to implement precise layout persistence.
Lastly, please accept my apologies if any part of this explanation is unclear; English is not my native language, and I have used AI to help translate my thoughts. Thank you for your time and for creating such a sophisticated and powerful tool.
Best regards,
BobLiu