|
@@ -1,10 +1,12 @@
|
|
|
import {
|
|
import {
|
|
|
- forwardRef, useMemo, useRef, useEffect, useState,
|
|
|
|
|
|
|
+ forwardRef, useMemo, useRef, useEffect, useState, useCallback,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
import { indentUnit } from '@codemirror/language';
|
|
import { indentUnit } from '@codemirror/language';
|
|
|
import { Prec, Extension } from '@codemirror/state';
|
|
import { Prec, Extension } from '@codemirror/state';
|
|
|
-import { EditorView, highlightActiveLine, highlightActiveLineGutter } from '@codemirror/view';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ keymap, type Command, EditorView, highlightActiveLine, highlightActiveLineGutter,
|
|
|
|
|
+} from '@codemirror/view';
|
|
|
import { AcceptedUploadFileType } from '@growi/core';
|
|
import { AcceptedUploadFileType } from '@growi/core';
|
|
|
import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
|
|
|
|
|
@@ -12,9 +14,11 @@ import { GlobalCodeMirrorEditorKey } from '../../consts';
|
|
|
import {
|
|
import {
|
|
|
useFileDropzone, FileDropzoneOverlay, getEditorTheme, type EditorTheme, getKeymap, type KeyMapMode,
|
|
useFileDropzone, FileDropzoneOverlay, getEditorTheme, type EditorTheme, getKeymap, type KeyMapMode,
|
|
|
} from '../../services';
|
|
} from '../../services';
|
|
|
|
|
+import { insertNewlineContinueMarkup } from '../../services/list-util/insert-newline-continue-markup';
|
|
|
import {
|
|
import {
|
|
|
adjustPasteData, getStrFromBol,
|
|
adjustPasteData, getStrFromBol,
|
|
|
} from '../../services/paste-util/paste-markdown-util';
|
|
} from '../../services/paste-util/paste-markdown-util';
|
|
|
|
|
+import { insertNewRowToMarkdownTable, isInTable } from '../../services/table-util/insert-new-row-to-table-markdown';
|
|
|
import { useCodeMirrorEditorIsolated } from '../../stores';
|
|
import { useCodeMirrorEditorIsolated } from '../../stores';
|
|
|
|
|
|
|
|
import { Toolbar } from './Toolbar';
|
|
import { Toolbar } from './Toolbar';
|
|
@@ -91,6 +95,27 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
}, [codeMirrorEditor, styleActiveLine]);
|
|
}, [codeMirrorEditor, styleActiveLine]);
|
|
|
|
|
|
|
|
|
|
+ const onPressEnter: Command = useCallback((editor) => {
|
|
|
|
|
+ if (isInTable(editor) && autoFormatMarkdownTable) {
|
|
|
|
|
+ insertNewRowToMarkdownTable(editor);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ insertNewlineContinueMarkup(editor);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }, [autoFormatMarkdownTable]);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+
|
|
|
|
|
+ const extension = keymap.of([
|
|
|
|
|
+ { key: 'Enter', run: onPressEnter },
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ const cleanupFunction = codeMirrorEditor?.appendExtensions?.(extension);
|
|
|
|
|
+ return cleanupFunction;
|
|
|
|
|
+
|
|
|
|
|
+ }, [codeMirrorEditor, onPressEnter]);
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const handlePaste = (event: ClipboardEvent) => {
|
|
const handlePaste = (event: ClipboardEvent) => {
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|