Restore auto-resizing of the code console input prompts#17819
Restore auto-resizing of the code console input prompts#17819jtpio merged 15 commits intojupyterlab:mainfrom
Conversation
|
Thanks for making a pull request to jupyterlab! |
|
Do people think this should be put behind a setting, so users can opt-out of the new behavior? |
Thinking more about this, it's probably fine without the setting, as the behavior in this PR feels a little bit more natural in the end. |
|
Made a couple of tweaks to the UX. Overall this PR now brings the following improvements:
jupyterlab-code-console-prompt-resize.mp4 |
|
The failing UI tests are tracked in #17820
Otherwise, marking as ready, so folks can try the UX (hopefully Binder will be back soon). |
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Thanks, @jtpio! Confirming that this looks good and works well from my end 👍🏻 Besides the NumPy website PR, I also highlighted this issue in jupyterlite/jupyterlite-sphinx#290, where I had previously attempted to (incorrectly) fix the problem in the JupyterLite codebase.
Do people think this should be put behind a setting, so users can opt-out of the new behavior?
Thinking more about this, it's probably fine without the setting, as the behavior in this PR feels a little bit more natural in the end.
This was reported as a regression in 4.4 by some users, so looking into fixing it for 4.5.
I agree; this PR is definitely a nice restoration of the original behaviour and shouldn't need to be opted out of.
I've also added a few comments below, and I hope they are helpful somewhat:
| return; | ||
| } | ||
|
|
||
| const remainingHeight = totalHeight - inputHeight; |
There was a problem hiding this comment.
Hmm, what would happen if inputHeight exceeds totalHeight, i.e., for very tall content? Should we have something like const maxInputHeight = Math.min(inputHeight, totalHeight * 0.8) here, or does SplitPanel clamp negative values to 0?
If yes, we could also consider if we want to refactor this math into a _calculateSizes function or similar, as I think _adjustSplitPanelForInputGrowth alone is doing quite a lot :)
There was a problem hiding this comment.
Normally it should not be possible for inputHeight to be greater than totalHeight, since totalHeight corresponds to the height of the SplitPanel and the input widget is one of the splits.
packages/console/src/widget.ts
Outdated
| // Detect height changes | ||
| if (promptCell.node) { | ||
| this._promptResizeObserver = new ResizeObserver(() => { | ||
| if (!this._hasManualResize) { | ||
| this._resetInputSize(); | ||
| } | ||
| requestAnimationFrame(() => { | ||
| this._adjustSplitPanelForInputGrowth(); | ||
| }); | ||
| }); | ||
| this._promptResizeObserver.observe(promptCell.node); | ||
| } | ||
|
|
There was a problem hiding this comment.
Not sure about any performance considerations or what the previous implementation was like, but would this cause a lot of redraws unless we debounce it?
There was a problem hiding this comment.
I think the previous implementation was just using flex, so it was offloaded to the browser, but otherwise, yeah, I was thinking about adding some debouncing to this.
The main idea is that we need to catch any change to the height of the prompt cell, which happens most of the time when a user adds a new line.
| private _translator: ITranslator; | ||
| private _splitPanel: SplitPanel; | ||
| private _promptResizeObserver: ResizeObserver | null = null; | ||
| private _hasManualResize = false; |
There was a problem hiding this comment.
| private _hasManualResize = false; | |
| private _hasManualResize: boolean = false; |
There was a problem hiding this comment.
^ this is not needed as typescript can infer this type
|
|
||
| const afterPasteHeight = await codeConsoleInput.boundingBox(); | ||
| expect(afterPasteHeight).not.toBeNull(); | ||
| expect(afterPasteHeight!.height).toBeGreaterThan(initialHeight!.height); |
There was a problem hiding this comment.
Looks like this is flaky as per GitHub annotations?
packages/console/src/widget.ts
Outdated
| requestAnimationFrame(() => { | ||
| this._adjustSplitPanelForInputGrowth(); | ||
| }); |
There was a problem hiding this comment.
Do we need to delay this until next frame? I am not sure if this is the exact source of the issue, but it looks like each time I press enter a really visual jitter is present
jitter.webm
There was a problem hiding this comment.
Oh wow, I haven't experienced such jitter locally. Which browser is it?
iirc the delay was needed to be able to pick up the correct size. But I can try to take another look at it to double check.
There was a problem hiding this comment.
I tried it on Binder, and I’m noticing the same jitter on Brave browser as well.
There was a problem hiding this comment.
OK I could reproduce locally with Chrome 141:
jupyterlab-console-jitter.mp4
|
The last few commits should have fixes the jittering issues reported previously. It now looks better when testing locally: jupyterlab-auto-resize-code-consoles-improved.mp4 |
|
Marking this one as ready for review again. @krassowski @agriyakhetarpal if you would like to try the new version on Binder, that would break, thanks! https://mybinder.org/v2/gh/jtpio/jupyterlab/auto-resize-code-console-inputs?urlpath=lab |
|
Thanks for the review! |
…le input prompts
…rompts (#18160) Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
…7819) * Auto-resize the code console input prompts * Add UI test * Handle moving the prompt cell with code in it * timeout * try to improve the resize logic * improve UX * fix jittering * integrity * more integrity fixes * fix promptCell * fix package.json * stabilize tests * snapshot update

References
Fixes #17597
Also reported in:
This was reported as a regression in 4.4 by some users, so looking into fixing it for 4.5.
Code changes
Use a
ResizeObserverto check changes in height for the input prompt cell to automatically set the split relative sizes.This only applies when
promptCellPositionis set tobottomortop.User-facing changes
This PR now brings the following improvements:
bottomandtop)jupyterlab-code-console-prompt-resize.mp4
Backwards-incompatible changes
None