CmdPal: Fix image overflow in Details panel#47385
Conversation
…dth to true Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/ddeb4f16-2a6e-49c0-9d10-6f0a85473496 Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a regression in CmdPal’s markdown image rendering where images in Details.Body could render at their natural (large) dimensions and overflow the Details panel by restoring “fit to column width” as the default behavior when no fit hint is provided.
Changes:
- Adjust
ImageProvider.GetImage()to treat missing--x-cmdpal-fitas “fit” (FitColumnWidth = true) while still allowing opt-out via--x-cmdpal-fit=none. - Update the Sample Pages markdown image documentation/examples to reflect
fitas the default andnoneas the opt-out.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/MarkdownImageProviders/ImageProvider.cs | Restores default “fit to column width” behavior when no fit hint is present. |
| src/modules/cmdpal/ext/SamplePagesExtension/Pages/SampleMarkdownImagesPage.cs | Updates sample docs/examples to match the new default fit semantics and demonstrate opt-out. |
| { | ||
| DownscaleOnly = imageSource.Hints.DownscaleOnly ?? true, | ||
| FitColumnWidth = imageSource.Hints.FitMode == "fit", | ||
| FitColumnWidth = imageSource.Hints.FitMode is null or "fit", | ||
| MaxWidthDip = imageSource.Hints.MaxPixelWidth, | ||
| MaxHeightDip = imageSource.Hints.MaxPixelHeight, |
There was a problem hiding this comment.
Fixed — the FitMode check in ImageProvider now uses StringComparison.OrdinalIgnoreCase, so mixed-case query values still take the fit path.
| - `none`: no automatic scaling, provides image as is | ||
| - `--x-cmdpal-upscale` | ||
| - `true`: allow upscaling | ||
| - `false`: downscale only (default) |
There was a problem hiding this comment.
Added a note to the sample Markdown images page calling out that the no-fit sample uses source pixel size, so it can differ from the natural visual size under non-100% DPI scaling.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot please re-review the latest changes. |
|
Can you please add before and after screenshots of this change? |
Images in
Details.Bodymarkdown regressed in v0.93.0: plainrenders at natural dimensions (e.g. 1280px) instead of being constrained to the panel width, causing horizontal overflow with no scroll.Summary of the Pull Request
ImageProvider.GetImage()explicitly setFitColumnWidth = imageSource.Hints.FitMode == "fit", which evaluates tofalsewhen no?--x-cmdpal-fit=fitquery parameter is present — overriding theInlineImageOptions.FitColumnWidth = truedefault inRtbInlineImageFactory.Changes:
ImageProvider.cs: Changed condition toFitMode is null || FitMode.Equals("fit", StringComparison.OrdinalIgnoreCase)so the default (no hint) correctly fits to column width, mixed-case values like?--x-cmdpal-fit=Fitare handled correctly, and users can opt out with?--x-cmdpal-fit=none.SampleMarkdownImagesPage.cs: Updated docs to reflectfitas the default; changed the "No scaling" example to use?--x-cmdpal-fit=none; added a note that the no-fit path uses source pixel dimensions which may differ from the natural visual size under non-100% DPI scaling.Fit semantics after fix:
FitColumnWidthtrue(default)true(explicit, case-insensitive)false(opt-out)PR Checklist
Detailed Description of the Pull Request / Additional comments
RtbInlineImageFactory.InlineImageOptions.FitColumnWidthdefaults totrue, andUpdate()usesrtb.ActualWidthto cap image size to the column. The bug was thatImageProvideralways passed an explicitfalseunless?--x-cmdpal-fit=fitwas in the URL, bypassing that default entirely. The fix also switches to a case-insensitive string comparison so query values likeFitorFITare treated identically tofit.Validation Steps Performed
markdown in aDetails.Bodyis now constrained to the Details panel width (restores v0.92.1 behavior).?--x-cmdpal-fit=nonedisables fitting for images that should render at natural (pixel) size.?--x-cmdpal-fit=fitand mixed-case variants (e.g.?--x-cmdpal-fit=Fit) still take the fit path.