This commit is contained in:
tamaina 2023-07-26 07:33:17 +00:00
parent 51cf5c57f0
commit 9f79e494f5
1 changed files with 22 additions and 29 deletions

View File

@ -268,16 +268,12 @@ async function adjustScroll(fn: () => void): Promise<void> {
} }
denyMoveTransition.value = true; denyMoveTransition.value = true;
fn(); fn();
return await nextTick(() => { return await nextTick().then(() => {
try {
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight); const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
scroll(scrollableElement, { top, behavior: 'instant' }); scroll(scrollableElement, { top, behavior: 'instant' });
// scrollableElementOrHtmlundefined // scrollableElementOrHtmlundefined
scrollableElementOrHtml.removeEventListener('wheel', preventDefault); scrollableElementOrHtml.removeEventListener('wheel', preventDefault);
scrollableElementOrHtml.removeEventListener('touchmove', preventDefault); scrollableElementOrHtml.removeEventListener('touchmove', preventDefault);
} catch (err) {
console.error(err, { scrollableElementOrHtml });
}
}).then(() => nextTick()).finally(() => { }).then(() => nextTick()).finally(() => {
denyMoveTransition.value = false; denyMoveTransition.value = false;
}); });
@ -523,7 +519,7 @@ const prepend = (item: MisskeyEntity): void => {
*/ */
function unshiftItems(newItems: MisskeyEntity[], limit = displayLimit.value) { function unshiftItems(newItems: MisskeyEntity[], limit = displayLimit.value) {
const length = newItems.length + items.value.size; const length = newItems.length + items.value.size;
items.value = new Map([...arrayToEntries(newItems), ...items.value].slice(0, limit)); items.value = new Map([...arrayToEntries(newItems), ...(newItems.length >= limit ? [] : items.value)].slice(0, limit));
if (length >= limit) more.value = true; if (length >= limit) more.value = true;
} }
@ -542,29 +538,26 @@ function concatItems(oldItems: MisskeyEntity[]) {
async function executeQueue() { async function executeQueue() {
if (queue.value.size === 0) return; if (queue.value.size === 0) return;
if (isPausingUpdateByExecutingQueue.value) return; if (isPausingUpdateByExecutingQueue.value) return;
if (isWebKit) {
// Safari
const newItems = Array.from(queue.value.values()).slice(-1 * props.pagination.limit);
unshiftItems(newItems);
queue.value = new Map();
} else {
const queueArr = Array.from(queue.value.entries()); const queueArr = Array.from(queue.value.entries());
queue.value = new Map(queueArr.slice(props.pagination.limit)); queue.value = new Map(queueArr.slice(props.pagination.limit));
const newItems = Array.from({ length: Math.min(queueArr.length, props.pagination.limit) }, (_, i) => queueArr[i][1]).reverse(); const newItems = Array.from({ length: Math.min(queueArr.length, props.pagination.limit) }, (_, i) => queueArr[i][1]).reverse();
isPausingUpdateByExecutingQueue.value = true; isPausingUpdateByExecutingQueue.value = true;
if (isWebKit) {
// Safari
scrollBy(scrollableElement, { top: TOLERANCE + 4, behavior: 'instant' });
backed = true;
denyMoveTransition.value = true;
await nextTick();
unshiftItems(newItems, Infinity);
await nextTick();
} else {
await adjustScroll(() => unshiftItems(newItems, Infinity)); await adjustScroll(() => unshiftItems(newItems, Infinity));
backed = true; backed = true;
denyMoveTransition.value = true;
}
denyMoveTransition.value = true;
items.value = new Map([...items.value].slice(0, displayLimit.value)); items.value = new Map([...items.value].slice(0, displayLimit.value));
await nextTick(); await nextTick();
isPausingUpdateByExecutingQueue.value = false; isPausingUpdateByExecutingQueue.value = false;
denyMoveTransition.value = false; denyMoveTransition.value = false;
}
} }
function prependQueue(newItem: MisskeyEntity) { function prependQueue(newItem: MisskeyEntity) {