mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
Merge pull request #10222 from kashaf-ansari-dev/fix-9053-restore-editor-scroll-position
Fix 9053 restore editor scroll position
This commit is contained in:
@@ -749,12 +749,13 @@ export const useEditor = (
|
|||||||
await postMessage(NativeEvents.title, item.title, tabId);
|
await postMessage(NativeEvents.title, item.title, tabId);
|
||||||
overlay(false);
|
overlay(false);
|
||||||
|
|
||||||
|
const updatedTab = useTabStore.getState().getTab(tabId!);
|
||||||
await postMessage(
|
await postMessage(
|
||||||
NativeEvents.html,
|
NativeEvents.html,
|
||||||
{
|
{
|
||||||
data: currentContents.current[item.id]?.data || "",
|
data: currentContents.current[item.id]?.data || "",
|
||||||
scrollTop: tab?.session?.scrollTop,
|
scrollTop: updatedTab?.session?.scrollTop,
|
||||||
selection: tab?.session?.selection,
|
selection: updatedTab?.session?.selection,
|
||||||
searchResultIndex: event.searchResultIndex
|
searchResultIndex: event.searchResultIndex
|
||||||
},
|
},
|
||||||
tabId,
|
tabId,
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ export function useEditorController({
|
|||||||
wordCounter: null,
|
wordCounter: null,
|
||||||
scroll: null
|
scroll: null
|
||||||
});
|
});
|
||||||
|
const hasRestored = useRef(false);
|
||||||
|
|
||||||
if (!tabRef.current.session?.noteId && loading) {
|
if (!tabRef.current.session?.noteId && loading) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -300,6 +301,7 @@ export function useEditorController({
|
|||||||
|
|
||||||
const scroll = useCallback(
|
const scroll = useCallback(
|
||||||
(_event: React.UIEvent<HTMLDivElement, UIEvent>) => {
|
(_event: React.UIEvent<HTMLDivElement, UIEvent>) => {
|
||||||
|
if (!hasRestored.current) return;
|
||||||
const value = _event.currentTarget.scrollTop;
|
const value = _event.currentTarget.scrollTop;
|
||||||
if (timers.current.scroll !== null) clearTimeout(timers.current.scroll);
|
if (timers.current.scroll !== null) clearTimeout(timers.current.scroll);
|
||||||
timers.current.scroll = setTimeout(() => {
|
timers.current.scroll = setTimeout(() => {
|
||||||
@@ -367,6 +369,7 @@ export function useEditorController({
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollTo?.(value.scrollTop || 0);
|
scrollTo?.(value.scrollTop || 0);
|
||||||
|
hasRestored.current = true;
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
countWords(0);
|
countWords(0);
|
||||||
}
|
}
|
||||||
@@ -382,6 +385,7 @@ export function useEditorController({
|
|||||||
logger("info", "LOADING NOTE HTML");
|
logger("info", "LOADING NOTE HTML");
|
||||||
if (!editor) break;
|
if (!editor) break;
|
||||||
update(value.scrollTop, value.selection, value.searchResultIndex);
|
update(value.scrollTop, value.selection, value.searchResultIndex);
|
||||||
|
hasRestored.current = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
countWords(0);
|
countWords(0);
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|||||||
Reference in New Issue
Block a user