diff --git a/wax-prosemirror-services/src/MultipleDropDownService/components/ContainerEditor.js b/wax-prosemirror-services/src/MultipleDropDownService/components/ContainerEditor.js index 52cd05c1037fce932a1e44333531c9035e4a7230..dc63bd1b5474e40e979b1545a4669cb873066fe1 100644 --- a/wax-prosemirror-services/src/MultipleDropDownService/components/ContainerEditor.js +++ b/wax-prosemirror-services/src/MultipleDropDownService/components/ContainerEditor.js @@ -3,10 +3,15 @@ import React, { useContext, useRef, useEffect } from 'react'; import styled from 'styled-components'; import { EditorView } from 'prosemirror-view'; -import { EditorState, TextSelection } from 'prosemirror-state'; +import { EditorState, TextSelection, NodeSelection } from 'prosemirror-state'; import { StepMap } from 'prosemirror-transform'; +import { + splitListItem, + liftListItem, + sinkListItem, +} from 'prosemirror-schema-list'; import { keymap } from 'prosemirror-keymap'; -import { baseKeymap } from 'prosemirror-commands'; +import { baseKeymap, chainCommands } from 'prosemirror-commands'; import { undo, redo } from 'prosemirror-history'; import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core'; @@ -55,15 +60,46 @@ const ContainerEditor = ({ node, view, getPos }) => { const createKeyBindings = () => { const keys = getKeys(); Object.keys(baseKeymap).forEach(key => { - keys[key] = baseKeymap[key]; + if (keys[key]) { + keys[key] = chainCommands(keys[key], baseKeymap[key]); + } else { + keys[key] = baseKeymap[key]; + } }); return keys; }; + const pressEnter = (state, dispatch) => { + if (state.selection.node && state.selection.node.type.name === 'image') { + const { $from, to } = state.selection; + + const same = $from.sharedDepth(to); + + const pos = $from.before(same); + dispatch(state.tr.setSelection(NodeSelection.create(state.doc, pos))); + return true; + } + // LISTS + if (splitListItem(state.schema.nodes.list_item)(state)) { + splitListItem(state.schema.nodes.list_item)(state, dispatch); + return true; + } + + return false; + }; + const getKeys = () => { return { 'Mod-z': () => undo(view.state, view.dispatch), 'Mod-y': () => redo(view.state, view.dispatch), + 'Mod-[': liftListItem(view.state.schema.nodes.list_item), + 'Mod-]': sinkListItem(view.state.schema.nodes.list_item), + // Enter: () => + // splitListItem(questionView.state.schema.nodes.list_item)( + // questionView.state, + // questionView.dispatch, + // ), + Enter: pressEnter, }; }; diff --git a/wax-prosemirror-services/src/MultipleDropDownService/schema/multipleDropDownContainerNode.js b/wax-prosemirror-services/src/MultipleDropDownService/schema/multipleDropDownContainerNode.js index 83884cd92d03f4ce4c124e4395e4ae8ada494e88..88a2cc6504159ed032667d41dbbaa34e5d7036d7 100644 --- a/wax-prosemirror-services/src/MultipleDropDownService/schema/multipleDropDownContainerNode.js +++ b/wax-prosemirror-services/src/MultipleDropDownService/schema/multipleDropDownContainerNode.js @@ -8,6 +8,7 @@ const multipleDropDownContainerNode = { atom: true, selectable: false, draggable: false, + defining: true, content: 'block*', parseDOM: [ {