Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix webview views not updating correctly on scroll #122887

Merged
merged 1 commit into from May 6, 2021

Conversation

mjbvz
Copy link
Contributor

@mjbvz mjbvz commented May 4, 2021

Fixes #110450

This fixes two issues with webview views that are inside view pane containers that are overflowing:

  • When a container with webview views is scrolled, we need to update the positon of the webview

  • If the webview is then scrolled outside of the container, we need to make sure it is clipped so it does not draw on top of other interface elements

Both of these are required since the webview is not part of the normal editor dom. Instead it is a top level element that is absolutely positioned in the slot it needs to me

@mjbvz mjbvz added this to the May 2021 milestone May 4, 2021
@mjbvz mjbvz requested review from joaomoreno and sbatten May 4, 2021 00:39
@mjbvz
Copy link
Contributor Author

mjbvz commented May 4, 2021

@sbatten and @joaomoreno Please look at the changes to the split view and view panes to let me know if this approach is ok or if there's a better way to accomplish this. If things look good, I'll go ahead and update the other files in the codebase to pass through the new parameters

@@ -237,6 +237,9 @@ export class SplitView<TLayoutContext = undefined> extends Disposable {
private _onDidSashReset = this._register(new Emitter<number>());
readonly onDidSashReset = this._onDidSashReset.event;

private _onScroll = this._register(new Emitter<ScrollEvent>());
Copy link
Member

Choose a reason for hiding this comment

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

This emitter doesn't need to exist. We can just this.onScroll = this.scrollableElement.onScroll, right?

@@ -286,7 +287,7 @@ export abstract class Pane extends Disposable implements IView {
}

protected abstract renderHeader(container: HTMLElement): void;
protected abstract renderBody(container: HTMLElement): void;
protected abstract renderBody(container: HTMLElement, rootContainer: HTMLElement): void;
Copy link
Member

Choose a reason for hiding this comment

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

This makes me itchy. 🙈

Copy link
Member

@joaomoreno joaomoreno May 4, 2021

Choose a reason for hiding this comment

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

I think this is a hack, but I also can't propose a good solution. Nevertheless, my rule for hacks is: keep them as contained as possible. In that mindset, couldn't we simply navigate up the parent DOM chain in layoutWebview(), find the element we assume to be the root element and use that? The hack would not spread to other files and would also not change component API.

Precedence:

// hack
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-no-twistie');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think that should be possible. As you note, it will require touching less code but could break if the parent dom structure changes (such as if an element's class is renamed)

I originally tried using intersection observers for this but couldn't get them working as I needed

Copy link
Member

Choose a reason for hiding this comment

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

intersection observers

TIL!

@mjbvz mjbvz force-pushed the webview-relayout-on-scroll branch from 097b8e0 to 900ddc2 Compare May 5, 2021 21:12
mjbvz added a commit to mjbvz/vscode that referenced this pull request May 5, 2021
Fixes microsoft#122887

This fixes two issues with webview views that are inside view pane containers that are overflowing:

When a container with webview views is scrolled, we need to update the positon of the webview

If the webview is then scrolled outside of the container, we need to make sure it is clipped so it does not draw on top of other interface elements

Both of these are required since the webview is not part of the normal editor dom. Instead it is a top level element that is absolutely positioned in the slot it needs to me
Fixes microsoft#122887

This fixes two issues with webview views that are inside view pane containers that are overflowing:

When a container with webview views is scrolled, we need to update the positon of the webview

If the webview is then scrolled outside of the container, we need to make sure it is clipped so it does not draw on top of other interface elements

Both of these are required since the webview is not part of the normal editor dom. Instead it is a top level element that is absolutely positioned in the slot it needs to me
@mjbvz mjbvz force-pushed the webview-relayout-on-scroll branch from 900ddc2 to c36655a Compare May 5, 2021 21:26
@mjbvz mjbvz merged commit 88c1322 into microsoft:main May 6, 2021
@mjbvz
Copy link
Contributor Author

mjbvz commented May 6, 2021

Merging this so we can get some testing. Let me know if you have any concerns about the implementation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug positioning of webview in explorer
2 participants