mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
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:
parent
cdfc446763
commit
6308c6c4b0
@ -412,35 +412,7 @@ class InputModel {
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
const historyDiv = elem.closest(".cmd-history");
|
||||
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;
|
||||
}
|
||||
elem.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
|
||||
grabSelectedHistoryItem(): void {
|
||||
|
Loading…
Reference in New Issue
Block a user