From 88f25dec4dc03c1360f3964c74cd04ef53fd94f1 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 28 Jan 2019 17:52:46 +0100 Subject: [PATCH] don't over-constraint layout while resizing adapting the approach taken in the prototype --- src/resizer/distributors/roomsublist2.js | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/resizer/distributors/roomsublist2.js b/src/resizer/distributors/roomsublist2.js index d6bf8d6c7a..57a07ecda3 100644 --- a/src/resizer/distributors/roomsublist2.js +++ b/src/resizer/distributors/roomsublist2.js @@ -41,6 +41,14 @@ export class Layout { this._sectionHeights = Object.assign({}, initialSizes); // in-progress heights, while dragging. Committed on mouse-up. this._heights = []; + // use while manually resizing to cancel + // the resize for a given mouse position + // when the previous resize made the layout + // constrained + this._clampedOffset = 0; + // used while manually resizing, to clear + // _clampedOffset when the direction of resizing changes + this._lastOffset = 0; } setAvailableHeight(newSize) { @@ -268,6 +276,22 @@ export class Layout { this._sectionHeights[section.id] = this._heights[i]; }); } + + _setUncommittedSectionHeight(sectionIndex, offset) { + if (Math.sign(offset) != Math.sign(this._lastOffset)) { + this._clampedOffset = undefined; + } + if (this._clampedOffset !== undefined) { + if (offset < 0 && offset < this._clampedOffset) { + return; + } + if (offset > 0 && offset > this._clampedOffset) { + return; + } + } + this._clampedOffset = this._relayout(sectionIndex, offset); + this._lastOffset = offset; + } } class Handle { @@ -278,7 +302,10 @@ class Handle { } setHeight(height) { - this._layout._relayout(this._sectionIndex, height - this._initialHeight); + this._layout._setUncommittedSectionHeight( + this._sectionIndex, + height - this._initialHeight, + ); return this; }