@atlaskit/editor-plugin-clear-marks-on-empty-doc
Version:
Clear marks on empty doc plugin for @atlaskit/editor-core
27 lines • 946 B
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { isEmptyDocument } from '@atlaskit/editor-common/utils';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
var pluginKey = new PluginKey('clearMarksOnChangeToEmptyDocumentPlugin');
function createPlugin() {
return new SafePlugin({
key: pluginKey,
appendTransaction: function 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 var clearMarksOnEmptyDocPlugin = function clearMarksOnEmptyDocPlugin() {
return {
name: 'clearMarksOnEmptyDoc',
pmPlugins: function pmPlugins() {
return [{
name: 'clearMarksOnChange',
plugin: createPlugin
}];
}
};
};