Simplify scrollHistoryItemIntoView method (#595)

* Simplify scrollHistoryItemIntoView

* remove unnecessary block argument

* actually the block nearest is necessary, otherwise the scroll will jump even if the item is already in view
This commit is contained in:
Evan Simkowitz 2024-04-23 15:38:02 -07:00 committed by GitHub
parent cdfc446763
commit 6308c6c4b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -412,35 +412,7 @@ class InputModel {
if (elem == null) { if (elem == null) {
return; return;
} }
const historyDiv = elem.closest(".cmd-history"); elem.scrollIntoView({ block: "nearest" });
if (historyDiv == null) {
return;
}
const buffer = 15;
let titleHeight = 24;
const titleDiv: HTMLElement = document.querySelector(".cmd-history .history-title");
if (titleDiv != null) {
titleHeight = titleDiv.offsetHeight + 2;
}
const elemOffset = elem.offsetTop;
const elemHeight = elem.clientHeight;
const topPos = historyDiv.scrollTop;
const endPos = topPos + historyDiv.clientHeight;
if (elemOffset + elemHeight + buffer > endPos) {
if (elemHeight + buffer > historyDiv.clientHeight - titleHeight) {
historyDiv.scrollTop = elemOffset - titleHeight;
return;
}
historyDiv.scrollTop = elemOffset - historyDiv.clientHeight + elemHeight + buffer;
return;
}
if (elemOffset < topPos + titleHeight) {
if (elemHeight + buffer > historyDiv.clientHeight - titleHeight) {
historyDiv.scrollTop = elemOffset - titleHeight;
return;
}
historyDiv.scrollTop = elemOffset - titleHeight - buffer;
}
} }
grabSelectedHistoryItem(): void { grabSelectedHistoryItem(): void {