Yuki Takei 3 дней назад
Родитель
Сommit
9285c6863e

+ 2 - 1
packages/editor/src/client/stores/use-collaborative-editor-mode-scroll.spec.ts

@@ -27,6 +27,7 @@ type AwarenessState = {
 
 type FakeEditorView = {
   dispatch: ReturnType<typeof vi.fn>;
+  scrollDOM: { style: { scrollBehavior: string } };
 };
 
 // Import the pure function after it is implemented.
@@ -59,7 +60,7 @@ describe('createScrollToRemoteCursorFn — Task 16.2', () => {
       doc: ydoc,
     };
 
-    view = { dispatch: vi.fn() };
+    view = { dispatch: vi.fn(), scrollDOM: { style: { scrollBehavior: '' } } };
   });
 
   describe('Task 16.2 — configuration callback receives a scroll function', () => {

+ 9 - 0
packages/editor/src/client/stores/use-collaborative-editor-mode.ts

@@ -61,9 +61,18 @@ export const createScrollToRemoteCursorFn = (
     const view = getView();
     if (view == null) return;
 
+    // Enable smooth scroll for this navigation, then restore
+    const { scrollDOM } = view;
+    const prevBehavior = scrollDOM.style.scrollBehavior;
+    scrollDOM.style.scrollBehavior = 'smooth';
+
     view.dispatch({
       effects: EditorView.scrollIntoView(pos.index, { y: 'center' }),
     });
+
+    setTimeout(() => {
+      scrollDOM.style.scrollBehavior = prevBehavior;
+    }, 500);
   };
 };