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

add list support

parent 1494ec59
No related branches found
No related tags found
1 merge request!359new node structure
...@@ -7,9 +7,14 @@ import { EditorView } from 'prosemirror-view'; ...@@ -7,9 +7,14 @@ import { EditorView } from 'prosemirror-view';
import { EditorState, TextSelection } from 'prosemirror-state'; import { EditorState, TextSelection } 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 } from 'prosemirror-commands'; import { baseKeymap, chainCommands } from 'prosemirror-commands';
import { undo, redo } from 'prosemirror-history'; import { undo, redo } from 'prosemirror-history';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import {
splitListItem,
liftListItem,
sinkListItem,
} from 'prosemirror-schema-list';
import Placeholder from '../plugins/placeholder'; import Placeholder from '../plugins/placeholder';
const EditorWrapper = styled.div` const EditorWrapper = styled.div`
...@@ -40,7 +45,6 @@ const EditorWrapper = styled.div` ...@@ -40,7 +45,6 @@ const EditorWrapper = styled.div`
} }
} }
`; `;
const QuestionEditorComponent = ({ node, view, getPos }) => { const QuestionEditorComponent = ({ node, view, getPos }) => {
const editorRef = useRef(); const editorRef = useRef();
...@@ -56,7 +60,11 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -56,7 +60,11 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
const createKeyBindings = () => { const createKeyBindings = () => {
const keys = getKeys(); const keys = getKeys();
Object.keys(baseKeymap).forEach(key => { 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; return keys;
}; };
...@@ -65,6 +73,13 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -65,6 +73,13 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
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-]': sinkListItem(view.state.schema.nodes.list_item),
Enter: () =>
splitListItem(questionView.state.schema.nodes.list_item)(
questionView.state,
questionView.dispatch,
),
}; };
}; };
...@@ -105,14 +120,6 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -105,14 +120,6 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
), ),
), ),
); );
// context.view[activeViewId].dispatch(
// context.view[activeViewId].state.tr.setSelection(
// TextSelection.between(
// context.view[activeViewId].state.selection.$anchor,
// context.view[activeViewId].state.selection.$head,
// ),
// ),
// );
context.updateView({}, questionId); context.updateView({}, questionId);
// Kludge to prevent issues due to the fact that the whole // Kludge to prevent issues due to the fact that the whole
// footnote is node-selected (and thus DOM-selected) when // footnote is node-selected (and thus DOM-selected) when
......
...@@ -9,11 +9,15 @@ export default props => { ...@@ -9,11 +9,15 @@ export default props => {
props: { props: {
decorations: state => { decorations: state => {
const decorations = []; const decorations = [];
const isList =
state.doc.content.content[0].type.name !== 'orderedlist' ||
state.doc.content.content[0].type.name !== 'bulletlist';
const decorate = (node, pos) => { const decorate = (node, pos) => {
if ( if (
node.type.isBlock && node.type.isBlock &&
node.childCount === 0 && node.childCount === 0 &&
state.doc.content.childCount === 1 state.doc.content.childCount === 1 &&
!isList
) { ) {
decorations.push( decorations.push(
Decoration.node(pos, pos + node.nodeSize, { Decoration.node(pos, pos + node.nodeSize, {
......
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