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

track list deletions

parent 12d5e95b
No related branches found
No related tags found
1 merge request!146Images lists
import { redo } from 'prosemirror-history'; import { redo } from 'prosemirror-history';
import Tools from '../../lib/Tools';
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { icons } from 'wax-prosemirror-components'; import { icons } from 'wax-prosemirror-components';
import Tools from '../../lib/Tools';
export default export default
@injectable() @injectable()
...@@ -12,7 +12,7 @@ class Redo extends Tools { ...@@ -12,7 +12,7 @@ class Redo extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
redo(state, tr => dispatch(tr.setMeta('inputType', 'historyRedo'))); redo(state, tr => dispatch(tr.setMeta('inputType', 'Redo')));
}; };
} }
......
...@@ -12,7 +12,7 @@ class Undo extends Tools { ...@@ -12,7 +12,7 @@ class Undo extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
undo(state, tr => dispatch(tr.setMeta('inputType', 'historyUndo'))); undo(state, tr => dispatch(tr.setMeta('inputType', 'Undo')));
}; };
} }
......
...@@ -33,10 +33,10 @@ const backSpaceShortCut = (state, dispatch, view) => ...@@ -33,10 +33,10 @@ const backSpaceShortCut = (state, dispatch, view) =>
); );
const undoShortCut = (state, dispatch, view) => const undoShortCut = (state, dispatch, view) =>
undo(state, tr => dispatch(tr.setMeta('inputType', 'historyUndo')), view); undo(state, tr => dispatch(tr.setMeta('inputType', 'Undo')), view);
const redoShortCut = (state, dispatch, view) => const redoShortCut = (state, dispatch, view) =>
redo(state, tr => dispatch(tr.setMeta('inputType', 'historyRedo')), view); redo(state, tr => dispatch(tr.setMeta('inputType', 'Redo')), view);
@injectable() @injectable()
class ShortCuts { class ShortCuts {
......
...@@ -25,14 +25,12 @@ class AcceptTrackChange extends Tools { ...@@ -25,14 +25,12 @@ class AcceptTrackChange extends Tools {
node.attrs.track && node.attrs.track &&
node.attrs.track.find(track => track.type === 'deletion') node.attrs.track.find(track => track.type === 'deletion')
) { ) {
console.log('here?');
removeNode(tr, node, pos, map); removeNode(tr, node, pos, map);
} }
if ( if (
node.marks && node.marks &&
node.marks.find(mark => mark.type.name === 'deletion') node.marks.find(mark => mark.type.name === 'deletion')
) { ) {
console.log('or here?', node);
const deletionStep = new ReplaceStep( const deletionStep = new ReplaceStep(
map.map(Math.max(pos, from)), map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)), map.map(Math.min(pos + node.nodeSize, to)),
......
import markDeletion from "./markDeletion"; import markDeletion from './markDeletion';
import markInsertion from "./markInsertion"; import markInsertion from './markInsertion';
import markWrapping from "./markWrapping"; import markWrapping from './markWrapping';
const replaceAroundStep = ( const replaceAroundStep = (
state, state,
...@@ -11,7 +11,7 @@ const replaceAroundStep = ( ...@@ -11,7 +11,7 @@ const replaceAroundStep = (
doc, doc,
user, user,
date, date,
group group,
) => { ) => {
if (step.from === step.gapFrom && step.to === step.gapTo) { if (step.from === step.gapFrom && step.to === step.gapTo) {
// wrapped in something // wrapped in something
...@@ -23,7 +23,7 @@ const replaceAroundStep = ( ...@@ -23,7 +23,7 @@ const replaceAroundStep = (
// unwrapped from something // unwrapped from something
map.appendMap(step.invert(doc).getMap()); map.appendMap(step.invert(doc).getMap());
map.appendMap( map.appendMap(
markDeletion(newTr, step.from, step.gapFrom, user, date, group) markDeletion(newTr, step.from, step.gapFrom, user, date, group),
); );
} else if ( } else if (
step.slice.size === 2 && step.slice.size === 2 &&
...@@ -41,30 +41,30 @@ const replaceAroundStep = ( ...@@ -41,30 +41,30 @@ const replaceAroundStep = (
step.slice.content.firstChild, step.slice.content.firstChild,
user, user,
date, date,
group group,
); );
} }
} else { } else {
console.log("to fix"); console.log('to fix');
// newTr.step(step); newTr.step(step);
// const ranges = [ const ranges = [
// { {
// from: step.getMap().map(step.from, -1), from: step.getMap().map(step.from, -1),
// to: step.getMap().map(step.gapFrom) to: step.getMap().map(step.gapFrom),
// }, },
// { {
// from: step.getMap().map(step.gapTo, -1), from: step.getMap().map(step.gapTo, -1),
// to: step.getMap().map(step.to) to: step.getMap().map(step.to),
// } },
// ]; ];
// ranges.forEach(range => ranges.forEach(range =>
// doc.nodesBetween(range.from, range.to, (node, pos) => { doc.nodesBetween(range.from, range.to, (node, pos) => {
// if (pos < range.from) { if (pos < range.from) {
// return true; return true;
// } }
// markInsertion(newTr, range.from, range.to, user, date); markInsertion(newTr, range.from, range.to, user, date);
// }) }),
// ); );
} }
}; };
......
import { ReplaceStep } from 'prosemirror-transform'; import { ReplaceStep } from 'prosemirror-transform';
import { CellSelection } from 'prosemirror-tables';
import { DocumentHelpers } from 'wax-prosemirror-utilities'; import { DocumentHelpers } from 'wax-prosemirror-utilities';
import markDeletion from './markDeletion'; import markDeletion from './markDeletion';
import markInsertion from './markInsertion'; import markInsertion from './markInsertion';
const replaceStep = (state, tr, step, newTr, map, doc, user, date, group) => { const replaceStep = (state, tr, step, newTr, map, doc, user, date, group) => {
const cellDeleteTr =
['backwardsDelete', 'deleteContentForward'].includes(
tr.getMeta('inputType'),
) && state.selection instanceof CellSelection;
// if deletion mark move to the end of deletion
const deletionMarkSchema = state.schema.marks.deletion; const deletionMarkSchema = state.schema.marks.deletion;
const deletionMark = DocumentHelpers.findMark( const deletionMark = DocumentHelpers.findMark(
state, state,
...@@ -20,14 +13,12 @@ const replaceStep = (state, tr, step, newTr, map, doc, user, date, group) => { ...@@ -20,14 +13,12 @@ const replaceStep = (state, tr, step, newTr, map, doc, user, date, group) => {
); );
const positionTo = deletionMark ? deletionMark.to : step.to; const positionTo = deletionMark ? deletionMark.to : step.to;
const newStep = !cellDeleteTr const newStep = new ReplaceStep(
? new ReplaceStep( positionTo, // We insert all the same steps, but with "from"/"to" both set to "to" in order not to delete content. Mapped as needed.
positionTo, // We insert all the same steps, but with "from"/"to" both set to "to" in order not to delete content. Mapped as needed. positionTo,
positionTo, step.slice,
step.slice, step.structure,
step.structure, );
)
: false;
// We didn't apply the original step in its original place. We adjust the map accordingly. // We didn't apply the original step in its original place. We adjust the map accordingly.
map.appendMap(step.invert(doc).getMap()); map.appendMap(step.invert(doc).getMap());
......
...@@ -25,17 +25,18 @@ const trackedTransaction = (tr, state, user) => { ...@@ -25,17 +25,18 @@ const trackedTransaction = (tr, state, user) => {
} }
} }
// images // images
// if (tr.meta.inputType === 'backwardsDelete' && !tr.steps.lenght) return tr; if (tr.meta.inputType === 'backwardsDelete' && !tr.steps.lenght) {
const $pos = state.selection.$anchor;
if ($pos.depth === 1) return tr;
}
if ( if (
!tr.steps.length || !tr.steps.length ||
(tr.meta && (tr.meta &&
!Object.keys(tr.meta).every(metadata => !Object.keys(tr.meta).every(meta =>
['inputType', 'uiEvent', 'paste', 'outsideView'].includes(metadata), ['inputType', 'uiEvent', 'paste'].includes(meta),
)) || )) ||
['historyUndo', 'historyRedo', 'AcceptReject'].includes( ['AcceptReject', 'Undo', 'Redo'].includes(tr.getMeta('inputType'))
tr.getMeta('inputType'),
)
) { ) {
return tr; return tr;
} }
...@@ -48,9 +49,7 @@ const trackedTransaction = (tr, state, user) => { ...@@ -48,9 +49,7 @@ const trackedTransaction = (tr, state, user) => {
tr.steps.forEach(originalStep => { tr.steps.forEach(originalStep => {
const step = originalStep.map(map); const step = originalStep.map(map);
const { doc } = newTr; const { doc } = newTr;
if (!step) { if (!step) return;
return;
}
switch (step.constructor) { switch (step.constructor) {
case ReplaceStep: case ReplaceStep:
...@@ -101,8 +100,21 @@ const trackedTransaction = (tr, state, user) => { ...@@ -101,8 +100,21 @@ const trackedTransaction = (tr, state, user) => {
const caretPos = map.map(tr.selection.from - 2, -1); const caretPos = map.map(tr.selection.from - 2, -1);
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos))); newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
} else { } else {
if (state.selection.from === state.selection.to) { if (
console.log('to fix for lists'); state.selection.from === state.selection.to &&
tr.selection.$head.depth > 1
) {
tr.steps.forEach(originalStep => {
const step = originalStep.map(map);
step.from += 1;
step.to += 1;
const { doc } = newTr;
replaceStep(state, tr, step, newTr, map, doc, user, date, group);
});
const caretPos = map.map(tr.selection.from - 1, -1);
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
} else if (state.selection.from === state.selection.to) {
const caretPos = map.map(tr.selection.from, -1); const caretPos = map.map(tr.selection.from, -1);
newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos))); newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
} }
......
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