-
Notifications
You must be signed in to change notification settings - Fork 26.3k
feat(docs-infra): saves the scroll position before the change of loca… #28037
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ export class AppComponent implements OnInit { | |
} | ||
if (path === this.currentPath) { | ||
// scroll only if on same page (most likely a change to the hash) | ||
this.autoScroll(); | ||
this.scrollService.scroll(); | ||
} else { | ||
// don't scroll; leave that to `onDocRendered` | ||
this.currentPath = path; | ||
|
@@ -187,11 +187,6 @@ export class AppComponent implements OnInit { | |
.subscribe(() => this.updateShell()); | ||
} | ||
|
||
// Scroll to the anchor in the hash fragment or top of doc. | ||
autoScroll() { | ||
this.scrollService.scroll(); | ||
} | ||
|
||
onDocReady() { | ||
// About to transition to new view. | ||
this.isTransitioning = true; | ||
|
@@ -204,9 +199,7 @@ export class AppComponent implements OnInit { | |
} | ||
|
||
onDocRemoved() { | ||
// The previous document has been removed. | ||
// Scroll to top to restore a clean visual state for the new document. | ||
this.scrollService.scrollToTop(); | ||
this.scrollService.removeStoredScrollPosition(); | ||
} | ||
|
||
onDocInserted() { | ||
|
@@ -216,9 +209,8 @@ export class AppComponent implements OnInit { | |
// (e.g. sidenav, host classes) needs to happen asynchronously. | ||
setTimeout(() => this.updateShell()); | ||
|
||
// Scroll 500ms after the new document has been inserted into the doc-viewer. | ||
// The delay is to allow time for async layout to complete. | ||
setTimeout(() => this.autoScroll(), 500); | ||
wKoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Scroll the good position depending on the context | ||
this.scrollService.scrollAfterRender(500); | ||
} | ||
|
||
onDocRendered() { | ||
|
@@ -256,7 +248,6 @@ export class AppComponent implements OnInit { | |
|
||
@HostListener('click', ['$event.target', '$event.button', '$event.ctrlKey', '$event.metaKey', '$event.altKey']) | ||
onClick(eventTarget: HTMLElement, button: number, ctrlKey: boolean, metaKey: boolean, altKey: boolean): boolean { | ||
|
||
// Hide the search results if we clicked outside both the "search box" and the "search results" | ||
if (!this.searchElements.some(element => element.nativeElement.contains(eventTarget))) { | ||
this.hideSearchResults(); | ||
|
@@ -348,6 +339,9 @@ export class AppComponent implements OnInit { | |
// Dynamically change height of table of contents container | ||
@HostListener('window:scroll') | ||
onScroll() { | ||
|
||
this.scrollService.updateScrollPositionInHistory(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had asked me the question when I wanted to use the scroll event. For the moment, I did not feel any lag. But, it is an option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Chrome (desktop), after some scrolling, I start to get the following warnings in the console:
So, I believe it is a good idea to do some throttling/debouncing here. |
||
|
||
if (!this.tocMaxHeightOffset) { | ||
// Must wait until `mat-toolbar` is measurable. | ||
const el = this.hostElement.nativeElement as Element; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the comment from here? I think this is the right place for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the method is
onDocRemoved
. I think the first line is redundant.The second line have to be removed. We stop to scrollToTop() when the Doc is removed.