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

reject insertions/deletions

parent e7329b36
No related branches found
No related tags found
1 merge request!143Track changes
......@@ -13,6 +13,7 @@
"inversify": "^5.0.1",
"inversify-inject-decorators": "^3.1.0",
"lodash": "^4.17.4",
"prosemirror-model": "^1.9.1",
"prosemirror-commands": "^1.1.3",
"prosemirror-history": "^1.1.3",
"prosemirror-keymap": "^1.1.3",
......
......@@ -18,7 +18,7 @@ class AcceptTrackChange extends Tools {
tr,
selection: { from, to },
} = state;
tr.setMeta('AcceptReject', true);
const map = new Mapping();
state.doc.nodesBetween(from, to, (node, pos) => {
......@@ -49,8 +49,7 @@ class AcceptTrackChange extends Tools {
);
}
});
dispatch(tr);
if (tr.steps.length) dispatch(tr);
};
}
......
import { Mapping, RemoveMarkStep, ReplaceStep } from 'prosemirror-transform';
import { Slice } from 'prosemirror-model';
import { injectable } from 'inversify';
import Tools from '../../lib/Tools';
......@@ -8,7 +10,44 @@ class RejectTrackChange extends Tools {
content = 'Reject';
get run() {
return (state, dispatch) => {};
return (state, dispatch) => {
const {
tr,
selection: { from, to },
} = state;
tr.setMeta('AcceptReject', true);
const map = new Mapping();
state.doc.nodesBetween(from, to, (node, pos) => {
if (
node.marks &&
node.marks.find(mark => mark.type.name === 'deletion')
) {
const deletionMark = node.marks.find(
mark => mark.type.name === 'deletion',
);
tr.step(
new RemoveMarkStep(
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
deletionMark,
),
);
} else if (
node.marks &&
node.marks.find(mark => mark.type.name === 'insertion')
) {
const deletionStep = new ReplaceStep(
map.map(Math.max(pos, from)),
map.map(Math.min(pos + node.nodeSize, to)),
Slice.empty,
);
tr.step(deletionStep);
map.appendMap(deletionStep.getMap());
}
});
if (tr.steps.length) dispatch(tr);
};
}
get active() {
......
......@@ -4,35 +4,37 @@ check: https://github.com/fiduswriter/fiduswriter/blob/develop/fiduswriter/docum
License included in folder.
*/
import { Selection, TextSelection } from "prosemirror-state";
import { Selection, TextSelection } from 'prosemirror-state';
import {
ReplaceStep,
ReplaceAroundStep,
AddMarkStep,
RemoveMarkStep,
Mapping
} from "prosemirror-transform";
Mapping,
} from 'prosemirror-transform';
import { DocumentHelpers } from "wax-prosemirror-utilities";
import { DocumentHelpers } from 'wax-prosemirror-utilities';
import replaceStep from "./helpers/replaceStep";
import replaceAroundStep from "./helpers/replaceAroundStep";
import addMarkStep from "./helpers/addMarkStep";
import removeMarkStep from "./helpers/removeMarkStep";
import replaceStep from './helpers/replaceStep';
import replaceAroundStep from './helpers/replaceAroundStep';
import addMarkStep from './helpers/addMarkStep';
import removeMarkStep from './helpers/removeMarkStep';
const trackedTransaction = (tr, state, user) => {
if (
!tr.steps.length ||
(tr.meta &&
!Object.keys(tr.meta).every(metadata =>
["inputType", "uiEvent", "paste", "outsideView"].includes(metadata)
['inputType', 'uiEvent', 'paste', 'outsideView'].includes(metadata),
)) ||
["historyUndo", "historyRedo"].includes(tr.getMeta("inputType"))
['historyUndo', 'historyRedo', 'AcceptReject'].includes(
tr.getMeta('inputType'),
)
) {
return tr;
}
const group = tr.getMeta("outsideView") ? tr.getMeta("outsideView") : "main";
const group = tr.getMeta('outsideView') ? tr.getMeta('outsideView') : 'main';
const newTr = state.tr;
const map = new Mapping();
const date = Math.floor(Date.now() / 300000);
......@@ -60,11 +62,11 @@ const trackedTransaction = (tr, state, user) => {
}
});
if (tr.getMeta("inputType")) {
newTr.setMeta(tr.getMeta("inputType"));
if (tr.getMeta('inputType')) {
newTr.setMeta(tr.getMeta('inputType'));
}
if (tr.getMeta("uiEvent")) {
newTr.setMeta(tr.getMeta("uiEvent"));
if (tr.getMeta('uiEvent')) {
newTr.setMeta(tr.getMeta('uiEvent'));
}
if (tr.selectionSet) {
......@@ -72,13 +74,13 @@ const trackedTransaction = (tr, state, user) => {
const deletionMark = DocumentHelpers.findMark(
state,
deletionMarkSchema,
false
false,
);
if (
tr.selection instanceof TextSelection &&
(tr.selection.from < state.selection.from ||
tr.getMeta("inputType") === "deleteContentBackward")
tr.getMeta('inputType') === 'deleteContentBackward')
) {
const caretPos = map.map(tr.selection.from, -1);
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