GeezerVison is showing github.com — fix(web): restore composer controls as space becomes available · pingdotgg/t3code@4268800
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/composerFooterLayout.test.ts +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -333,6 +333,33 @@ describe("resolveRestingComposerControlsLayout hysteresis", () => { | 333 | 333 | ).toEqual({ hiddenCount: 0, visible: true }); | 334 | 334 | }); | 335 | 335 |
| | 336 | + it("restores the blocks that fit when the full cluster has no slack", () => { | | 337 | + const partlyRestored = resolveRestingComposerControlsLayout({ | | 338 | + ...base, | | 339 | + hostWidth: 357, | | 340 | + previous: { hiddenCount: 2, visible: true }, | | 341 | + }); | | 342 | + expect(partlyRestored).toEqual({ hiddenCount: 1, visible: true }); | | 343 | + expect( | | 344 | + resolveRestingComposerControlsLayout({ ...base, hostWidth: 357, previous: partlyRestored }), | | 345 | + ).toEqual(partlyRestored); | | 346 | + expect( | | 347 | + resolveRestingComposerControlsLayout({ ...base, hostWidth: 358, previous: partlyRestored }), | | 348 | + ).toEqual({ hiddenCount: 0, visible: true }); | | 349 | + }); | | 350 | + | | 351 | + it("requires slack before partially restoring a cluster", () => { | | 352 | + // One inline block, the picker, and overflow need 149 + 60 + 24 + 8 = 241px. | | 353 | + const previous = { hiddenCount: 2, visible: true }; | | 354 | + expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 241, previous })).toEqual( | | 355 | + previous, | | 356 | + ); | | 357 | + expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 242, previous })).toEqual({ | | 358 | + hiddenCount: 1, | | 359 | + visible: true, | | 360 | + }); | | 361 | + }); | | 362 | + | 336 | 363 | it("still resolves from scratch when there is no previous layout", () => { | 337 | 364 | expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 357 })).toEqual({ | 338 | 365 | hiddenCount: 0, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/composerFooterLayout.ts +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,9 +134,13 @@ export function resolveRestingComposerControlsLayout( | 134 | 134 | // composer re-measures on every render, so without that margin a host | 135 | 135 | // sitting exactly on a threshold flips a block in and out until React | 136 | 136 | // gives up with "Maximum update depth exceeded". | 137 | | - if (previous && hiddenCount < previous.hiddenCount) { | 138 | | - if (restingComposerControlsWidth(input, hiddenCount) > hostWidth - RESTING_CONTROLS_SLACK_PX) { | 139 | | - hiddenCount = Math.min(previous.hiddenCount, blockWidths.length); | | 137 | + if (previous) { | | 138 | + const previousHiddenCount = Math.min(previous.hiddenCount, blockWidths.length); | | 139 | + while ( | | 140 | + hiddenCount < previousHiddenCount && | | 141 | + restingComposerControlsWidth(input, hiddenCount) > hostWidth - RESTING_CONTROLS_SLACK_PX | | 142 | + ) { | | 143 | + hiddenCount += 1; | 140 | 144 | } | 141 | 145 | } | 142 | 146 | const minimumWidth = restingComposerControlsWidth(input, hiddenCount, input.minimumFixedWidth); | |
|