diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index e5f77e92e204fb6234a2aa9f187d897a7364f482..d5f40e10da41329d275dba5fc252f4cae6c615be 100644 --- a/editors/demo/src/HHMI/config/config.js +++ b/editors/demo/src/HHMI/config/config.js @@ -35,7 +35,7 @@ import { import { DefaultSchema } from 'wax-prosemirror-utilities'; import invisibles, { hardBreak } from '@guardian/prosemirror-invisibles'; -const getContent = source => { +const getContentOnEnter = source => { console.log('editor content', source); }; @@ -68,7 +68,7 @@ export default { }, ], - // ChatService: { getContent }, + ChatService: { getContentOnEnter }, SchemaService: DefaultSchema, RulesService: [emDash, ellipsis], diff --git a/wax-prosemirror-plugins/src/ChatPlugin.js b/wax-prosemirror-plugins/src/ChatPlugin.js index 369932323b75a4b84a1d0c77890ffb90cb7e9499..63096466e9a2d7c7d4a6956714b7c58f35e16684 100644 --- a/wax-prosemirror-plugins/src/ChatPlugin.js +++ b/wax-prosemirror-plugins/src/ChatPlugin.js @@ -33,26 +33,38 @@ export default props => { }, props: { handleKeyDown(view, event) { + let isList = false; if (event.key === 'Enter' && !event.shiftKey) { if (view.state.doc.content.size <= 2) { return true; } - const WaxOptions = { - doc: {}, - schema: view.props.options.schema, - plugins: view.props.options.plugins, - }; - const parse = parser(view.props.options.schema); - WaxOptions.doc = parse(''); - - const serialize = serializer(view.props.options.schema); - props.getContent(serialize(view.state.doc.content)); - - view.updateState(EditorState.create(WaxOptions)); - if (view.dispatch) { - view.state.tr.setMeta('addToHistory', false); + const { + selection: { from, to }, + } = view.state; + + view.state.doc.nodesBetween(from, to, node => { + if (node.type.name === 'list_item') isList = true; + }); + + if (!isList) { + const serialize = serializer(view.props.options.schema); + props.getContentOnEnter(serialize(view.state.doc.content)); + + const WaxOptions = { + doc: {}, + schema: view.props.options.schema, + plugins: view.props.options.plugins, + }; + + const parse = parser(view.props.options.schema); + WaxOptions.doc = parse(''); + view.updateState(EditorState.create(WaxOptions)); + + if (view.dispatch) { + view.state.tr.setMeta('addToHistory', false); + } + return true; } - return true; } return false; },