Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #190 from wangeditor-team/feat-clear-editor-api
Browse files Browse the repository at this point in the history
feat: clear editor api
  • Loading branch information
wangfupeng1988 authored Sep 7, 2021
2 parents 64a91c3 + 01b07f2 commit a516f6b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/core/src/editor/dom-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import isEqual from 'lodash.isequal'
import toArray from 'lodash.toarray'
import { Editor, Node, Element, Path, Point, Range, Ancestor, Text } from 'slate'
import { Editor, Node, Element, Path, Point, Range, Ancestor, Text, Transforms } from 'slate'
import type { IDomEditor } from './interface'
import { Key } from '../utils/key'
import TextArea from '../text-area/TextArea'
Expand Down Expand Up @@ -721,4 +721,21 @@ export const DomEditor = {
}
}
},

clear(editor: IDomEditor) {
const initialEditorValue: Node[] = [
{
type: 'paragraph',
children: [{ text: '' }],
},
]
Transforms.removeNodes(editor, {
at: {
anchor: Editor.start(editor, []),
focus: Editor.end(editor, []),
},
mode: 'highest',
})
Transforms.insertNodes(editor, initialEditorValue)
},
}

0 comments on commit a516f6b

Please sign in to comment.