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

Collapse entry will scroll back to top of entry #1682

Merged
merged 3 commits into from
Dec 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class Display extends EventDispatcher {
/** @type {OptionToggleHotkeyHandler} */
this._optionToggleHotkeyHandler = new OptionToggleHotkeyHandler(this);
/** @type {ElementOverflowController} */
this._elementOverflowController = new ElementOverflowController();
this._elementOverflowController = new ElementOverflowController(this);
/** @type {boolean} */
this._frameVisible = (pageType === 'search');
/** @type {HTMLElement} */
Expand Down Expand Up @@ -381,6 +381,16 @@ export class Display extends EventDispatcher {
}
}

/**
* @param {Element} element
*/
scrollUpToElementTop(element) {
const top = this._getElementTop(element);
if (this._windowScroll.y > top) {
this._windowScroll.toY(top);
}
}

/**
* @param {{clearable?: boolean, useBrowserHistory?: boolean}} details
*/
Expand Down
12 changes: 10 additions & 2 deletions ext/js/display/element-overflow-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import {EventListenerCollection} from '../core/event-listener-collection.js';

export class ElementOverflowController {
constructor() {
/**
* @param {import('./display.js').Display} display
*/
constructor(display) {
/** @type {import('./display.js').Display} */
this._display = display;
/** @type {Element[]} */
this._elements = [];
/** @type {?(number|import('core').Timeout)} */
Expand Down Expand Up @@ -141,7 +146,10 @@ export class ElementOverflowController {
];
for (const collapsedElement of collapsedElements) {
if (collapsedElement === null) { continue; }
collapsedElement.classList.toggle('collapsed');
const collapsed = collapsedElement.classList.toggle('collapsed');
if (collapsed) {
this._display.scrollUpToElementTop(element);
}
}
}

Expand Down
Loading