soumaeda 2 лет назад
Родитель
Сommit
2a0ea7268b

+ 0 - 2
packages/editor/src/components/CodeMirrorEditor/Toolbar/TextFormatTools.tsx

@@ -3,7 +3,6 @@ import { useCallback, useState } from 'react';
 import { Collapse } from 'reactstrap';
 
 import type { GlobalCodeMirrorEditorKey } from '../../../consts';
-import { useInsertHeader } from '../../../services/codemirror-editor/use-codemirror-editor/utils/insert-header';
 import { useCodeMirrorEditorIsolated } from '../../../stores';
 
 import styles from './TextFormatTools.module.scss';
@@ -41,7 +40,6 @@ export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
   const { editorKey } = props;
   const [isOpen, setOpen] = useState(false);
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey);
-  const insertHeader = useInsertHeader();
 
   const toggle = useCallback(() => {
     setOpen(bool => !bool);

+ 0 - 31
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-header.ts

@@ -1,31 +0,0 @@
-import { useCallback } from 'react';
-
-import { EditorView } from '@codemirror/view';
-
-type InsertHeader = (view?: EditorView) => void;
-
-export const useInsertHeader = (): InsertHeader => {
-  return useCallback((view?: EditorView) => {
-    if (view == null) {
-      return;
-    }
-    let prefix = '#';
-    const cursorPos = view.state.selection.main.head;
-    const line = view.state.doc.lineAt(cursorPos);
-    const insertPos = line.text.startsWith(prefix) ? cursorPos - 1 : cursorPos;
-
-    if (!line.text.startsWith(prefix)) {
-      prefix += ' ';
-    }
-
-    view.dispatch({
-      changes: {
-        from: insertPos,
-        to: insertPos,
-        insert: prefix,
-      },
-      selection: { anchor: cursorPos + prefix.length },
-    });
-    view.focus();
-  }, []);
-};