mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
mobile: fix scroll jumping in realtime sync
This commit is contained in:
@@ -269,6 +269,7 @@ const Tiptap = ({
|
||||
? []
|
||||
: getTableOfContents(containerRef.current);
|
||||
},
|
||||
scrollTop: () => containerRef.current?.scrollTop || 0,
|
||||
scrollTo: (top) => {
|
||||
containerRef.current?.scrollTo({ top, behavior: "auto" });
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Editor, scrollIntoViewById } from "@notesnook/editor";
|
||||
import { strings } from "@notesnook/intl";
|
||||
import {
|
||||
ThemeDefinition,
|
||||
useThemeColors,
|
||||
@@ -41,7 +42,6 @@ import {
|
||||
import { injectCss, transform } from "../utils/css";
|
||||
import { pendingSaveRequests } from "../utils/pending-saves";
|
||||
import { useTabContext, useTabStore } from "./useTabStore";
|
||||
import { strings } from "@notesnook/intl";
|
||||
|
||||
type Attachment = {
|
||||
hash: string;
|
||||
@@ -126,11 +126,13 @@ export type EditorController = {
|
||||
export function useEditorController({
|
||||
update,
|
||||
getTableOfContents,
|
||||
scrollTo
|
||||
scrollTo,
|
||||
scrollTop
|
||||
}: {
|
||||
update: () => void;
|
||||
getTableOfContents: () => any[];
|
||||
scrollTo: (top: number) => void;
|
||||
scrollTop: () => number;
|
||||
}): EditorController {
|
||||
const passwordInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const tab = useTabContext();
|
||||
@@ -342,23 +344,22 @@ export function useEditorController({
|
||||
updateTabOnFocus.current = true;
|
||||
} else {
|
||||
if (!editor) break;
|
||||
|
||||
const noteState = tabRef.current?.noteId
|
||||
? useTabStore.getState().noteState[tabRef.current?.noteId]
|
||||
: null;
|
||||
|
||||
const top = scrollTop() || noteState?.top || 0;
|
||||
editor?.commands.setContent(htmlContentRef.current, false, {
|
||||
preserveWhitespace: true
|
||||
});
|
||||
|
||||
if (noteState) {
|
||||
if (noteState && editor.isFocused) {
|
||||
editor.commands.setTextSelection({
|
||||
from: noteState.from,
|
||||
to: noteState.to
|
||||
});
|
||||
}
|
||||
|
||||
scrollTo?.(noteState?.top || 0);
|
||||
scrollTo?.(top || 0);
|
||||
countWords(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user