docx-diff-editor 1.0.27 → 1.0.28

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.js CHANGED
@@ -193,6 +193,18 @@ function getMarksAtPosition(spans, pos) {
193
193
  }
194
194
  return [];
195
195
  }
196
+ function hasDefinedAttributes(marks) {
197
+ if (!marks || marks.length === 0) return false;
198
+ for (const mark of marks) {
199
+ if (!mark.attrs) continue;
200
+ for (const value of Object.values(mark.attrs)) {
201
+ if (value !== void 0 && value !== null) {
202
+ return true;
203
+ }
204
+ }
205
+ }
206
+ return marks.some((m) => !m.attrs);
207
+ }
196
208
  function detectFormatChanges(spansA, spansB, segments) {
197
209
  const formatChanges = [];
198
210
  let posA = 0;
@@ -216,13 +228,17 @@ function detectFormatChanges(spansA, spansB, segments) {
216
228
  break;
217
229
  }
218
230
  }
219
- formatChanges.push({
220
- from: posA + startI,
221
- to: posA + i,
222
- text: segment.text.substring(startI, i),
223
- before: startMarksA,
224
- after: startMarksB
225
- });
231
+ if (hasDefinedAttributes(startMarksB) || hasDefinedAttributes(startMarksA)) {
232
+ if (hasDefinedAttributes(startMarksB)) {
233
+ formatChanges.push({
234
+ from: posA + startI,
235
+ to: posA + i,
236
+ text: segment.text.substring(startI, i),
237
+ before: startMarksA,
238
+ after: startMarksB
239
+ });
240
+ }
241
+ }
226
242
  } else {
227
243
  i++;
228
244
  }