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