Fix mobile scroll preservation when returning from editor to note list
This commit is contained in:
1 parent
ee2ee84de6
commit
7096631f1e
1 file changed
+21
@@ -505,9 +505,14 @@ export default function EvercloneWorkspace() {
|
||||
await fetchSidebar();
|
||||
};
|
||||
|
||||
const listScrollPosRef = useRef<number>(0);
|
||||
|
||||
// Android / Browser Back Button support when zoomed into a note or drawer on mobile
|
||||
const openNoteInEditor = useCallback(
|
||||
(noteId: string) => {
|
||||
if (listParentRef.current) {
|
||||
listScrollPosRef.current = listParentRef.current.scrollTop;
|
||||
}
|
||||
setSelectedNoteId(noteId);
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768 && mobilePane !== 'editor') {
|
||||
window.history.pushState({ evcMobilePane: 'editor', noteId }, '');
|
||||
@@ -531,6 +536,22 @@ export default function EvercloneWorkspace() {
|
||||
return () => window.removeEventListener('popstate', onPopState);
|
||||
}, [mobileMenuOpen, activeView, mobilePane]);
|
||||
|
||||
// Restore list scroll position or scroll top when returning to list pane on mobile
|
||||
useEffect(() => {
|
||||
if (mobilePane === 'list' && listParentRef.current) {
|
||||
const targetScroll = listScrollPosRef.current;
|
||||
// Also ensure window itself is at top (prevent browser auto-scroll offset)
|
||||
if (typeof window !== 'undefined') {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
requestAnimationFrame(() => {
|
||||
if (listParentRef.current) {
|
||||
listParentRef.current.scrollTop = targetScroll;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [mobilePane]);
|
||||
|
||||
const handleSaveCurrentSearch = async () => {
|
||||
if (!searchQuery.trim()) return;
|
||||
const name = window.prompt('Name for this Saved Search:', searchQuery.trim());
|
||||
|
||||
Reference in new issue
Block a user