UNPKG

@atlaskit/editor-plugin-clear-marks-on-empty-doc

Version:

Clear marks on empty doc plugin for @atlaskit/editor-core

25 lines 847 B
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { isEmptyDocument } from '@atlaskit/editor-common/utils'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; const pluginKey = new PluginKey('clearMarksOnChangeToEmptyDocumentPlugin'); function createPlugin() { return new SafePlugin({ key: pluginKey, appendTransaction: (_transactions, oldState, newState) => { // ED-2973: When a user clears the editor's content, remove the current active marks if (!isEmptyDocument(oldState.doc) && isEmptyDocument(newState.doc)) { return newState.tr.setStoredMarks([]); } return; } }); } export const clearMarksOnEmptyDocPlugin = () => ({ name: 'clearMarksOnEmptyDoc', pmPlugins() { return [{ name: 'clearMarksOnChange', plugin: createPlugin }]; } });