Просмотр исходного кода

add effect for Unified merge view

Yuki Takei 1 год назад
Родитель
Сommit
a8685e85c4
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      packages/editor/src/client/stores/use-editor-settings.ts

+ 15 - 0
packages/editor/src/client/stores/use-editor-settings.ts

@@ -1,5 +1,6 @@
 import { useEffect, useCallback, useState } from 'react';
 
+import { unifiedMergeView } from '@codemirror/merge';
 import type { Extension } from '@codemirror/state';
 import { Prec } from '@codemirror/state';
 import {
@@ -93,4 +94,18 @@ export const useEditorSettings = (
   }, [codeMirrorEditor, keymapExtension]);
 
 
+  useEffect(() => {
+    if (editorSettings?.unifiedMergeView == null) {
+      return;
+    }
+    const extension = editorSettings.unifiedMergeView ? [
+      unifiedMergeView({
+        original: codeMirrorEditor?.getDoc() ?? '',
+      }),
+    ] : [];
+
+    const cleanupFunction = codeMirrorEditor?.appendExtensions?.(extension);
+    return cleanupFunction;
+  }, [codeMirrorEditor, editorSettings?.unifiedMergeView]);
+
 };