Skip to content

Try using anchor positioning for webview#307758

Open
mjbvz wants to merge 1 commit intomicrosoft:mainfrom
mjbvz:dev/mjbvz/safe-crab
Open

Try using anchor positioning for webview#307758
mjbvz wants to merge 1 commit intomicrosoft:mainfrom
mjbvz:dev/mjbvz/safe-crab

Conversation

@mjbvz
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz commented Apr 4, 2026

Fixes #307489

Not supported yet in all browsers so we still need the existing code too but I think should fix this case

Fixes microsoft#307489

Not supported yet in all browsers so we still need the existing code too but I think should fix this caese
Copilot AI review requested due to automatic review settings April 4, 2026 00:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to fix mis-positioned webview content (e.g. markdown preview in Sessions) when the window is moved by leveraging CSS Anchor Positioning so the overlay webview tracks its editor anchor between explicit layout calls.

Changes:

  • Add CSS Anchor Positioning setup/teardown when a webview is claimed (sets anchor-name on the editor host and position-anchor/top/left on the webview container).
  • Re-apply top/left: anchor(...) after layoutWebviewOverElement(...) overwrites positioning with explicit pixel values.
  • Import toDisposable to ensure the anchor-related inline styles are cleaned up with existing _webviewVisibleDisposables.
Show a summary per file
File Description
src/vs/workbench/contrib/webviewPanel/browser/webviewEditor.ts Adds anchor-positioning-based tracking for overlay webview placement to better handle window moves.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment on lines +194 to +203
// Use CSS Anchor Positioning to automatically track position changes.
// The editor element's parent acts as the CSS anchor, and the webview
// container is tethered to it
if (this._element?.parentElement) {
const anchorName = `--${this._element.id}`;
this._element.parentElement.style.setProperty('anchor-name', anchorName);
const container = input.webview.container;
container.style.setProperty('position-anchor', anchorName);
container.style.setProperty('top', 'anchor(top)');
container.style.setProperty('left', 'anchor(left)');
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new anchor-positioning code sets top/left to anchor(...) unconditionally. In browsers that don’t support CSS Anchor Positioning, assigning an unsupported value clears the inline top/left that layoutWebviewOverElement(...) just computed (see OverlayWebview.doLayoutWebviewOverElement), which can regress positioning instead of preserving the existing fallback. Please add runtime feature detection (e.g. CSS.supports(...)) and only apply anchor-name / position-anchor / top: anchor(...) / left: anchor(...) when supported, including in the re-apply logic in synchronizeWebviewContainerDimensions.

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75


Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two consecutive blank lines here; please remove the extra whitespace to keep formatting consistent with the surrounding code.

Suggested change

Copilot uses AI. Check for mistakes.
@mjbvz mjbvz changed the title Try using anchor positioning. Try using anchor positioning for webview Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sessions: Markdown preview text does not move with window

3 participants