@manuscripts/track-changes-plugin 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -4
- package/dist/index.js +30 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1213,8 +1213,31 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1213
1213
|
changeSteps.push(...deleteSteps);
|
|
1214
1214
|
log.info('TR: steps after applying delete', [...newTr.steps]);
|
|
1215
1215
|
log.info('DELETE STEPS: ', changeSteps);
|
|
1216
|
-
|
|
1217
|
-
|
|
1216
|
+
// console.log('CHANGE STEPS AT THIS POINT:')
|
|
1217
|
+
// console.log(JSON.parse(JSON.stringify(changeSteps)))
|
|
1218
|
+
function sameThingBackSpaced() {
|
|
1219
|
+
/*
|
|
1220
|
+
When deleting text with backspace and getting to the point of when a space and a character before a deleted piece of text is deleted
|
|
1221
|
+
the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
|
|
1222
|
+
It normally results in [delete, delete, insert] set of ChangSteps where the 1st delete is for the delete done by
|
|
1223
|
+
the backspace key, the second delete and the insert are a misinterpretation of the moved text. So these last 2 steps have to be caught
|
|
1224
|
+
and removed as they are not meaningful.
|
|
1225
|
+
*/
|
|
1226
|
+
if (changeSteps.length == 2 && newSliceContent.size > 0) {
|
|
1227
|
+
const correspondingDeletion = changeSteps.find(
|
|
1228
|
+
// @ts-ignore
|
|
1229
|
+
(step) => step.node.text === newSliceContent.content[0].text // @TODO - get more precise proof of match. E.g.: position approximation
|
|
1230
|
+
);
|
|
1231
|
+
return correspondingDeletion;
|
|
1232
|
+
}
|
|
1233
|
+
return undefined;
|
|
1234
|
+
}
|
|
1235
|
+
const backSpacedText = sameThingBackSpaced();
|
|
1236
|
+
if (backSpacedText) {
|
|
1237
|
+
changeSteps.splice(changeSteps.indexOf(backSpacedText));
|
|
1238
|
+
}
|
|
1239
|
+
const textWasDeleted = !!changeSteps.length;
|
|
1240
|
+
if (!backSpacedText && newSliceContent.size > 0) {
|
|
1218
1241
|
log.info('newSliceContent', newSliceContent);
|
|
1219
1242
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1220
1243
|
// the sides should be equal. TODO can they be other than 0?
|
|
@@ -1222,8 +1245,11 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1222
1245
|
const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
|
|
1223
1246
|
changeSteps.push({
|
|
1224
1247
|
type: 'insert-slice',
|
|
1225
|
-
from:
|
|
1226
|
-
to:
|
|
1248
|
+
from: textWasDeleted ? fromB : toA,
|
|
1249
|
+
to: textWasDeleted ? toB - 1 : toA,
|
|
1250
|
+
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1251
|
+
- it will gointo infinite loop if toB -1 is used
|
|
1252
|
+
*/
|
|
1227
1253
|
sliceWasSplit,
|
|
1228
1254
|
slice: new prosemirrorModel.Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1229
1255
|
});
|
package/dist/index.js
CHANGED
|
@@ -1205,8 +1205,31 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1205
1205
|
changeSteps.push(...deleteSteps);
|
|
1206
1206
|
log.info('TR: steps after applying delete', [...newTr.steps]);
|
|
1207
1207
|
log.info('DELETE STEPS: ', changeSteps);
|
|
1208
|
-
|
|
1209
|
-
|
|
1208
|
+
// console.log('CHANGE STEPS AT THIS POINT:')
|
|
1209
|
+
// console.log(JSON.parse(JSON.stringify(changeSteps)))
|
|
1210
|
+
function sameThingBackSpaced() {
|
|
1211
|
+
/*
|
|
1212
|
+
When deleting text with backspace and getting to the point of when a space and a character before a deleted piece of text is deleted
|
|
1213
|
+
the prosemirror would interpret it as moving the <del> node (this is a tracked deletion) one characted behind.
|
|
1214
|
+
It normally results in [delete, delete, insert] set of ChangSteps where the 1st delete is for the delete done by
|
|
1215
|
+
the backspace key, the second delete and the insert are a misinterpretation of the moved text. So these last 2 steps have to be caught
|
|
1216
|
+
and removed as they are not meaningful.
|
|
1217
|
+
*/
|
|
1218
|
+
if (changeSteps.length == 2 && newSliceContent.size > 0) {
|
|
1219
|
+
const correspondingDeletion = changeSteps.find(
|
|
1220
|
+
// @ts-ignore
|
|
1221
|
+
(step) => step.node.text === newSliceContent.content[0].text // @TODO - get more precise proof of match. E.g.: position approximation
|
|
1222
|
+
);
|
|
1223
|
+
return correspondingDeletion;
|
|
1224
|
+
}
|
|
1225
|
+
return undefined;
|
|
1226
|
+
}
|
|
1227
|
+
const backSpacedText = sameThingBackSpaced();
|
|
1228
|
+
if (backSpacedText) {
|
|
1229
|
+
changeSteps.splice(changeSteps.indexOf(backSpacedText));
|
|
1230
|
+
}
|
|
1231
|
+
const textWasDeleted = !!changeSteps.length;
|
|
1232
|
+
if (!backSpacedText && newSliceContent.size > 0) {
|
|
1210
1233
|
log.info('newSliceContent', newSliceContent);
|
|
1211
1234
|
// Since deleteAndMergeSplitBlockNodes modified the slice to not to contain any merged nodes,
|
|
1212
1235
|
// the sides should be equal. TODO can they be other than 0?
|
|
@@ -1214,8 +1237,11 @@ function trackReplaceStep(step, oldState, newTr, attrs, stepResult, currentStepD
|
|
|
1214
1237
|
const openEnd = slice.openStart !== slice.openEnd ? 0 : slice.openEnd;
|
|
1215
1238
|
changeSteps.push({
|
|
1216
1239
|
type: 'insert-slice',
|
|
1217
|
-
from:
|
|
1218
|
-
to:
|
|
1240
|
+
from: textWasDeleted ? fromB : toA,
|
|
1241
|
+
to: textWasDeleted ? toB - 1 : toA,
|
|
1242
|
+
/* it's not entirely clear why using "fromB" is needed at all but in cases where there areno content deleted before
|
|
1243
|
+
- it will gointo infinite loop if toB -1 is used
|
|
1244
|
+
*/
|
|
1219
1245
|
sliceWasSplit,
|
|
1220
1246
|
slice: new Slice(setFragmentAsInserted(newSliceContent, createNewInsertAttrs(attrs), oldState.schema), openStart, openEnd),
|
|
1221
1247
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/track-changes-plugin",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"author": "Atypon Systems LLC",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Atypon-OpenSource/manuscripts-quarterback/tree/main/quarterback-packages/track-changes-plugin",
|