mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
changes
This commit is contained in:
1 parent
67f70473ea
commit
19c4823d3d
4 files changed
+11
-7
No files matched your search
@@ -40,7 +40,8 @@ export function Editor({ chapterId, content, onChange, onReady }: EditorProps) {
|
||||
const scroller = editor.view.dom.closest(".editor-pane") as HTMLElement | null;
|
||||
|
||||
const previous = openChapter.current;
|
||||
if (previous !== chapterId) {
|
||||
const switching = previous !== chapterId;
|
||||
if (switching) {
|
||||
const { from, to } = editor.state.selection;
|
||||
positions.current.set(previous, { from, to, scroll: scroller?.scrollTop ?? 0 });
|
||||
}
|
||||
@@ -50,9 +51,12 @@ export function Editor({ chapterId, content, onChange, onReady }: EditorProps) {
|
||||
|
||||
const saved = positions.current.get(chapterId);
|
||||
const size = editor.state.doc.content.size;
|
||||
editor.commands.setTextSelection(
|
||||
saved ? { from: Math.min(saved.from, size), to: Math.min(saved.to, size) } : 0
|
||||
);
|
||||
const selection = saved ? { from: Math.min(saved.from, size), to: Math.min(saved.to, size) } : 0;
|
||||
if (switching) {
|
||||
editor.chain().setTextSelection(selection).focus(undefined, { scrollIntoView: false }).run();
|
||||
} else {
|
||||
editor.commands.setTextSelection(selection);
|
||||
}
|
||||
|
||||
if (scroller) {
|
||||
const top = saved?.scroll ?? 0;
|
||||
|
||||
Reference in new issue
Block a user