Compare commits

...

4 Commits

Author SHA1 Message Date
Ammar Ahmed
db7b3635e2 mobile: set sticky state if not set already 2024-11-06 13:12:29 +05:00
Ammar Ahmed
72e256a949 mobile: fix setting startingOffset 2024-11-06 13:08:30 +05:00
Ammar Ahmed
a81a788c74 mobile: fix editor status flickers too much 2024-11-06 13:06:09 +05:00
Ammar Ahmed
3eaba77c38 mobile: fix keep-in-view overscrolling 2024-11-06 13:05:53 +05:00
2 changed files with 37 additions and 8 deletions

View File

@@ -62,9 +62,12 @@ function StatusBar({
};
}, [tab.id, statusBar]);
const scrollState = useRef({
isMovingUp: false,
startingOffset: 0
});
const onScroll = React.useCallback((event: Event) => {
const currentOffset = (event.target as HTMLElement)?.scrollTop;
post("editor-event:scroll", currentOffset);
if (currentOffset < 200) {
if (stickyRef.current) {
stickyRef.current = false;
@@ -76,11 +79,39 @@ function StatusBar({
}
if (Date.now() - lastStickyChangeTime.current < 300) return;
if (currentOffset > prevScroll.current) {
setSticky(false);
stickyRef.current = false;
if (
!scrollState.current.startingOffset ||
scrollState.current.isMovingUp
) {
scrollState.current.startingOffset = currentOffset;
}
scrollState.current.isMovingUp = false;
} else {
setSticky(true);
stickyRef.current = true;
if (
!scrollState.current.startingOffset ||
!scrollState.current.isMovingUp
) {
scrollState.current.startingOffset = currentOffset;
}
scrollState.current.isMovingUp = true;
}
if (scrollState.current.isMovingUp) {
if (currentOffset < scrollState.current.startingOffset - 50) {
if (!stickyRef.current) {
stickyRef.current = true;
setSticky(true);
}
scrollState.current.startingOffset = 0;
}
} else {
if (currentOffset > scrollState.current.startingOffset + 50) {
if (stickyRef.current) {
stickyRef.current = false;
setSticky(false);
}
scrollState.current.startingOffset = 0;
}
}
lastStickyChangeTime.current = Date.now();
prevScroll.current = currentOffset;

View File

@@ -82,9 +82,7 @@ export function keepLastLineInView(
)
return;
const isPopupVisible = document.getElementsByClassName(
"editor-mobile-toolbar-popup"
);
const isPopupVisible = document.querySelector(".editor-mobile-toolbar-popup");
const node = editor.state.selection.$from;
if (node.pos > editor.state.doc.nodeSize) return;