@seafile/sdoc-editor 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,6 +217,11 @@ export const getAboveBlockNode = (editor, options) => {
217
217
  block: true
218
218
  }));
219
219
  };
220
+ export const getTopLevelBlockNode = editor => {
221
+ return getAboveBlockNode(editor, {
222
+ match: (n, p) => Element.isElement(n) && p.length === 1
223
+ });
224
+ };
220
225
  export const getPrevNode = editor => {
221
226
  const lowerNodeEntry = getAboveNode(editor, {
222
227
  mode: 'lowest',
@@ -1,8 +1,8 @@
1
1
  import { Editor, Node, Range, Transforms } from '@seafile/slate';
2
- import { QUICK_INSERT } from '../../../constants';
2
+ import { CODE_BLOCK, QUICK_INSERT } from '../../../constants';
3
3
  import { getBeforeText } from '../../list/helpers';
4
4
  import { genQuickInsert, getQuickInsertEntity, transformToText } from '../helper';
5
- import { focusEditor } from '../../../core';
5
+ import { focusEditor, getTopLevelBlockNode } from '../../../core';
6
6
  import { KeyCodes } from '../../../../../constants';
7
7
  const withQuickInsert = editor => {
8
8
  const {
@@ -14,6 +14,9 @@ const withQuickInsert = editor => {
14
14
  } = editor;
15
15
  const newEditor = editor;
16
16
  newEditor.insertText = text => {
17
+ if (!editor.selection) return insertText(text);
18
+ const [blockNode] = getTopLevelBlockNode(editor);
19
+ if (blockNode.type === CODE_BLOCK) return insertText(text);
17
20
  if (text === '/') {
18
21
  // Avoid triggering quick insert when the cursor is in the quick insert
19
22
  const isInQuickInsert = getQuickInsertEntity(editor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",