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

Add css shadow at the scroll region top #176569

Merged
merged 1 commit into from Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions extensions/notebook-renderers/src/index.ts
Expand Up @@ -216,17 +216,15 @@ function getPreviousOutputWithMatchingMimeType(container: HTMLElement, mimeType:
// if there is a scrollable output, it will be scrolled to the given value if provided or the bottom of the element
function appendChildAndScroll(container: HTMLElement, child: HTMLElement, scrollTop?: number) {
container.appendChild(child);
child.childNodes.forEach((node) => {
if (node instanceof HTMLElement && node.classList.contains(scrollableClass)) {
node.scrollTop = scrollTop !== undefined ? scrollTop : node.scrollHeight;
}
});
const scrollableElement = child.querySelector(`.${scrollableClass}`);
if (scrollableElement) {
scrollableElement.scrollTop = scrollTop !== undefined ? scrollTop : scrollableElement.scrollHeight;
}
}

// Find the scrollTop of the existing scrollable output, return undefined if at the bottom or element doesn't exist
function findScrolledHeight(outputContainer: HTMLElement, outputId: string): number | undefined {
const output = outputContainer.querySelector(`[output-item-id="${outputId}"]`);
const scrollableElement = output?.querySelector('.scrollable');
const scrollableElement = outputContainer.querySelector(`[output-item-id="${outputId}"] .${scrollableClass}`);
if (scrollableElement && scrollableElement.scrollHeight - scrollableElement.scrollTop - scrollableElement.clientHeight > 2) {
// not scrolled to the bottom
return scrollableElement.scrollTop;
Expand Down Expand Up @@ -338,6 +336,9 @@ export const activate: ActivationFunction<void> = (ctx) => {
box-sizing: border-box;
border-width: 1px;
}
.output .scrollable.more-above {
box-shadow: var(--vscode-scrollbar-shadow) 0 6px 6px -6px inset
}
.output-plaintext .code-bold,
.output-stream .code-bold,
.traceback .code-bold {
Expand Down
8 changes: 8 additions & 0 deletions extensions/notebook-renderers/src/textHelper.ts
Expand Up @@ -54,6 +54,14 @@ function truncatedArrayOfString(id: string, buffer: string[], linesLimit: number
function scrollableArrayOfString(id: string, buffer: string[], container: HTMLElement, trustHtml: boolean) {
const scrollableDiv = document.createElement('div');
scrollableDiv.classList.add(scrollableClass);
scrollableDiv.onscroll = (e) => {
Copy link
Contributor

@rzhao271 rzhao271 Mar 8, 2023

Choose a reason for hiding this comment

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

Could this be rewritten as a disposable listener, e.g. using someDisposableStore.add(DOM.addDisposableListener())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, definitely should do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const target = e.target as HTMLElement;
if (target.scrollTop === 0) {
target.classList.remove('more-above');
} else {
target.classList.add('more-above');
}
};

if (buffer.length > 5000) {
container.appendChild(generateViewMoreElement(id, false));
Expand Down