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