Skip to content
Snippets Groups Projects
Commit c1dd7a5a authored by chris's avatar chris
Browse files

enter support

parent 98c063df
No related branches found
No related tags found
1 merge request!359new node structure
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import React, { useContext, useRef, useEffect } from 'react'; import React, { useContext, useRef, useEffect } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { EditorView } from 'prosemirror-view'; import { EditorView } from 'prosemirror-view';
import { EditorState, TextSelection } from 'prosemirror-state'; import { EditorState, TextSelection, NodeSelection } from 'prosemirror-state';
import { StepMap } from 'prosemirror-transform'; import { StepMap } from 'prosemirror-transform';
import { keymap } from 'prosemirror-keymap'; import { keymap } from 'prosemirror-keymap';
import { baseKeymap, chainCommands } from 'prosemirror-commands'; import { baseKeymap, chainCommands } from 'prosemirror-commands';
...@@ -69,17 +69,37 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -69,17 +69,37 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
return keys; 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 = () => { const getKeys = () => {
return { return {
'Mod-z': () => undo(view.state, view.dispatch), 'Mod-z': () => undo(view.state, view.dispatch),
'Mod-y': () => redo(view.state, view.dispatch), 'Mod-y': () => redo(view.state, view.dispatch),
'Mod-[': liftListItem(view.state.schema.nodes.list_item), 'Mod-[': liftListItem(view.state.schema.nodes.list_item),
'Mod-]': sinkListItem(view.state.schema.nodes.list_item), 'Mod-]': sinkListItem(view.state.schema.nodes.list_item),
Enter: () => // Enter: () =>
splitListItem(questionView.state.schema.nodes.list_item)( // splitListItem(questionView.state.schema.nodes.list_item)(
questionView.state, // questionView.state,
questionView.dispatch, // questionView.dispatch,
), // ),
Enter: pressEnter,
}; };
}; };
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment