Чат и обсуждения: шапка не уезжает за экран при открытой клавиатуре

В поиске по переписке после ввода текста шапка с «раньше/позже» уезжала за верхний край
экрана, и переключать совпадения было нечем. Причина – scrollIntoView: он прокручивает не
только ленту, но и все внешние контейнеры и видимую область браузера, а при открытой
клавиатуре видимая область меньше экрана приложения. Теперь прокручивается только сама
лента (общий scrollNodeIntoContainer в services/scroll-utils.js): поиск и «перейти к
дате», переход к цитате, «к последнему», разделитель «Новые сообщения», а также переходы
к ответу и к записи в обсуждениях и ленте канала.
This commit is contained in:
q
2026-10-13 08:44:11 +03:00
parent 8c3751aba0
commit 42797b1a43
6 changed files with 48 additions and 26 deletions
+1 -1
View File
@@ -39,7 +39,7 @@
}());
</script>
<script>
window.__SHINE_BUILD_HASH__ = '20261013123000';
window.__SHINE_BUILD_HASH__ = '20261013130000';
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
</script>
<script>
+6 -5
View File
@@ -37,6 +37,7 @@ import { loadProfileSnapshot } from '../services/user-profile-params.js';
import { extractLoginFromBlockchainName, makeProfileRoute, makeShineChannelRoute, makeShineMessageRoute } from '../services/shine-routes.js';
import { parsePublicationOrdinal, publicationAtOrdinal, ordinalForPublication } from '../services/channel-message-ordinals.js';
import { dropPageData, pageDataAge, readPageData, writePageData } from '../services/page-data-cache.js';
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
export const pageMeta = { id: 'channel-thread-view', title: 'Обсуждение', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
const MSG_SUBTYPE_TEXT_POST = 10;
@@ -1355,7 +1356,7 @@ function applyPendingScroll(screen, routeKey, shouldContinue = () => true) {
const cards = screen.querySelectorAll('.thread-block--replies [data-message-key]');
const last = cards[cards.length - 1];
if (last) {
last.scrollIntoView({ behavior: 'smooth', block: 'center' });
scrollNodeIntoContainer(last, { behavior: 'smooth' });
}
pendingThreadScroll.delete(routeKey);
return;
@@ -1363,7 +1364,7 @@ function applyPendingScroll(screen, routeKey, shouldContinue = () => true) {
const node = screen.querySelector(`[data-message-key="${target}"]`);
if (node) {
node.scrollIntoView({ behavior: 'smooth', block: 'center' });
scrollNodeIntoContainer(node, { behavior: 'smooth' });
pendingThreadScroll.delete(routeKey);
}
};
@@ -1987,7 +1988,7 @@ export function render({ navigate, route, chrome }) {
};
returnBtn.addEventListener('click', () => {
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(returnKey)}"]`);
el?.scrollIntoView({ block: 'center', behavior: 'smooth' });
scrollNodeIntoContainer(el, { behavior: 'smooth' });
highlight(el);
returnBtn.hidden = true;
});
@@ -1998,7 +1999,7 @@ export function render({ navigate, route, chrome }) {
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(key)}"]`);
if (!el) return;
el.closest('.thread-replies')?.classList.add('is-expanded');
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
scrollNodeIntoContainer(el, { behavior: 'smooth' });
highlight(el);
returnKey = fromKey;
returnBtn.hidden = false;
@@ -2139,7 +2140,7 @@ export function render({ navigate, route, chrome }) {
if (!hasPendingScroll && !Number.isFinite(restorePosition) && focusWrap) {
trackTimer(window.setTimeout(() => {
if (disposed || seq !== refreshSeq || !focusWrap.isConnected) return;
focusWrap.scrollIntoView({ behavior: 'auto', block: 'start' });
scrollNodeIntoContainer(focusWrap, { block: 'start' });
}, 20));
}
};
+4 -5
View File
@@ -56,6 +56,7 @@ import {
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
import { dropPageData, readPageData, writePageData } from '../services/page-data-cache.js';
import { sortedChannelPublications } from '../services/channel-message-ordinals.js';
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
export const pageMeta = { id: 'channel-view', title: 'Канал', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
const CHANNEL_TYPE_STORIES = 0;
@@ -1034,7 +1035,7 @@ function flashAndScrollToMessage(messageRef) {
const target = cards.find((card) => card.dataset.messageKey === key);
if (!target) return false;
target.classList.remove('is-focus-flash');
target.scrollIntoView({ behavior: 'smooth', block: 'center' });
scrollNodeIntoContainer(target, { behavior: 'smooth' });
window.setTimeout(() => {
if (target.isConnected) target.classList.add('is-focus-flash');
}, 60);
@@ -1602,9 +1603,7 @@ function renderDemoFallback(screen, navigate, error) {
function scrollChannelToBottom(screen, smooth = true) {
const feed = screen.querySelector('.channel-feed');
if (feed) {
feed.scrollIntoView({ behavior: smooth ? 'smooth' : 'auto', block: 'end' });
}
if (feed) scrollNodeIntoContainer(feed, { block: 'end', behavior: smooth ? 'smooth' : 'auto' });
const appScreen = document.getElementById('app-screen');
if (appScreen) {
appScreen.scrollTo({ top: appScreen.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
@@ -1631,7 +1630,7 @@ function applyPendingScroll(screen, routeKey, forceBottom = false) {
const element = screen.querySelector(`[data-message-key="${target}"]`);
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
scrollNodeIntoContainer(element, { behavior: 'smooth' });
pendingScrollByRoute.delete(routeKey);
}
};
+5 -14
View File
@@ -53,6 +53,7 @@ import {
import { DM_CHAT_PREFS_EVENT, isDmChatMuted, isDmChatPinned, setDmChatPinned } from '../services/dm-chat-prefs.js';
import { createDmMuteMenuItem } from '../components/dm-mute-menu.js';
import { actionErrorText, mediaAccessErrorText } from '../services/ui-error-texts.js';
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
import { loadProfileSnapshot } from '../services/user-profile-params.js';
import { makeProfileLinksRoute, makeProfileRoute } from '../services/shine-routes.js';
import { openHistoryLayer } from '../router.js';
@@ -932,9 +933,7 @@ function scrollToLatestMessage(list) {
const scrollContainer = findChatScrollContainer(list);
const lastBubble = list.lastElementChild;
const apply = () => {
if (lastBubble?.scrollIntoView) {
lastBubble.scrollIntoView({ block: 'end', inline: 'nearest' });
}
scrollNodeIntoContainer(lastBubble, { container: scrollContainer, block: 'end' });
scrollContainer.scrollTop = scrollContainer.scrollHeight;
};
apply();
@@ -1092,15 +1091,11 @@ function createDmVoiceAttachmentCard(attachment) {
function scrollToLatestMessageSmart(list, { smoothIfNearBottom = false } = {}) {
if (!list) return;
const scrollContainer = findChatScrollContainer(list);
const lastBubble = list.lastElementChild;
const maxScrollTop = Math.max(0, scrollContainer.scrollHeight - scrollContainer.clientHeight);
const distanceToBottom = Math.max(0, maxScrollTop - scrollContainer.scrollTop);
const useSmooth = smoothIfNearBottom && distanceToBottom <= 180;
const apply = (behavior = useSmooth ? 'smooth' : 'auto') => {
if (lastBubble?.scrollIntoView) {
lastBubble.scrollIntoView({ block: 'end', inline: 'nearest', behavior });
}
if (behavior === 'smooth' && typeof scrollContainer.scrollTo === 'function') {
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior: 'smooth' });
} else {
@@ -1119,9 +1114,7 @@ function scrollToUnreadSeparator(list) {
if (!separator) return false;
const scrollContainer = findChatScrollContainer(list);
const apply = () => {
if (separator?.scrollIntoView) {
separator.scrollIntoView({ block: 'start', inline: 'nearest' });
}
scrollNodeIntoContainer(separator, { container: scrollContainer, block: 'start' });
const bottomSlack = 72;
scrollContainer.scrollTop = Math.max(0, scrollContainer.scrollTop - bottomSlack);
};
@@ -1273,9 +1266,7 @@ function renderLog(
replyBox.addEventListener('click', (event) => {
event.stopPropagation();
const targetNode = list.querySelector(`[data-base-key="${CSS.escape(String(replyTarget?.baseKey || ''))}"]`);
if (targetNode?.scrollIntoView) {
targetNode.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' });
}
scrollNodeIntoContainer(targetNode, { container: findChatScrollContainer(list), block: 'center', behavior: 'smooth' });
});
bubble.append(replyBox);
}
@@ -1691,7 +1682,7 @@ export function render({ navigate, route, chrome }) {
if (!node) return;
stickToBottom = false;
const distance = Math.abs(node.getBoundingClientRect().top - wrap.getBoundingClientRect().top - wrap.clientHeight / 2);
node.scrollIntoView({ block, behavior: distance < wrap.clientHeight ? 'smooth' : 'auto' });
scrollNodeIntoContainer(node, { container: wrap, block, behavior: distance < wrap.clientHeight ? 'smooth' : 'auto' });
};
const findBubble = (messageKey) => (messageKey
+31
View File
@@ -0,0 +1,31 @@
// Прокрутить к элементу только его ленту (ближайший прокручиваемый контейнер).
// element.scrollIntoView двигает ещё и все внешние контейнеры и видимую область браузера:
// при открытой клавиатуре это уводило шапку за верхний край экрана – в поиске по переписке
// пропадали «раньше/позже», после ответа в обсуждении – заголовок.
function findScrollContainer(node) {
for (let el = node?.parentElement; el; el = el.parentElement) {
const { overflowY } = getComputedStyle(el);
if ((overflowY === 'auto' || overflowY === 'scroll') && el.scrollHeight > el.clientHeight) return el;
}
return null;
}
/**
* @param {Element} node
* @param {{ container?: Element|null, block?: 'start'|'center'|'end', behavior?: 'auto'|'smooth' }} [opts]
*/
export function scrollNodeIntoContainer(node, { container = null, block = 'center', behavior = 'auto' } = {}) {
if (!node) return;
const host = container || findScrollContainer(node);
if (!host) return;
const hostRect = host.getBoundingClientRect();
const nodeRect = node.getBoundingClientRect();
let delta;
if (block === 'start') delta = nodeRect.top - hostRect.top;
else if (block === 'end') delta = nodeRect.bottom - hostRect.bottom;
else delta = nodeRect.top - hostRect.top - (host.clientHeight - nodeRect.height) / 2;
const top = Math.max(0, Math.min(host.scrollHeight - host.clientHeight, host.scrollTop + delta));
if (behavior === 'smooth' && typeof host.scrollTo === 'function') host.scrollTo({ top, behavior: 'smooth' });
else host.scrollTop = top;
}