@tiptap/core 2.5.0-beta.1 → 2.5.0-beta.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.umd.js CHANGED
@@ -3350,30 +3350,40 @@
3350
3350
  markType = getMarkType(typeOrName, state.schema);
3351
3351
  }
3352
3352
  if (dispatch) {
3353
- tr.selection.ranges.forEach(range => {
3353
+ let lastPos;
3354
+ let lastNode;
3355
+ let trimmedFrom;
3356
+ let trimmedTo;
3357
+ tr.selection.ranges.forEach((range) => {
3354
3358
  const from = range.$from.pos;
3355
3359
  const to = range.$to.pos;
3356
3360
  state.doc.nodesBetween(from, to, (node, pos) => {
3357
3361
  if (nodeType && nodeType === node.type) {
3358
- tr.setNodeMarkup(pos, undefined, {
3359
- ...node.attrs,
3360
- ...attributes,
3361
- });
3362
- }
3363
- if (markType && node.marks.length) {
3364
- node.marks.forEach(mark => {
3365
- if (markType === mark.type) {
3366
- const trimmedFrom = Math.max(pos, from);
3367
- const trimmedTo = Math.min(pos + node.nodeSize, to);
3368
- tr.addMark(trimmedFrom, trimmedTo, markType.create({
3369
- ...mark.attrs,
3370
- ...attributes,
3371
- }));
3372
- }
3373
- });
3362
+ trimmedFrom = Math.max(pos, from);
3363
+ trimmedTo = Math.min(pos + node.nodeSize, to);
3364
+ lastPos = pos;
3365
+ lastNode = node;
3374
3366
  }
3375
3367
  });
3376
3368
  });
3369
+ if (lastNode) {
3370
+ if (lastPos !== undefined) {
3371
+ tr.setNodeMarkup(lastPos, undefined, {
3372
+ ...lastNode.attrs,
3373
+ ...attributes,
3374
+ });
3375
+ }
3376
+ if (markType && lastNode.marks.length) {
3377
+ lastNode.marks.forEach((mark) => {
3378
+ if (markType === mark.type) {
3379
+ tr.addMark(trimmedFrom, trimmedTo, markType.create({
3380
+ ...mark.attrs,
3381
+ ...attributes,
3382
+ }));
3383
+ }
3384
+ });
3385
+ }
3386
+ }
3377
3387
  }
3378
3388
  return true;
3379
3389
  };