Skip to content

Commit

Permalink
always format in optimal order
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen authored and luin committed Jun 30, 2023
1 parent 0c6c032 commit 0877563
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions blots/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,28 @@ class Block extends BlockBlot {
this.cache = {};
}

formatAt(index, length, name, value) {
formatAt(index, length, format, value?) {
if (length <= 0) return;
if (this.scroll.query(name, Scope.BLOCK)) {
if (typeof format != 'string') {
const order = Inline.order.slice().reverse();
Object.keys(format)
.sort((a, b) => {
const aOrder = order.indexOf(a);
const bOrder = order.indexOf(b);
return aOrder - bOrder;
})
.forEach(key => {
this.formatAt(index, length, key, format[key]);
});
} else if (this.scroll.query(format, Scope.BLOCK)) {
if (index + length === this.length()) {
this.format(name, value);
this.format(format, value);
}
} else {
super.formatAt(
index,
Math.min(length, this.length() - index - 1),
name,
format,
value,
);
}
Expand Down Expand Up @@ -100,9 +111,7 @@ class Block extends BlockBlot {
this.insertAt(index, key, op.insert[key]);
}
}
Object.keys(attributes).forEach(name => {
this.formatAt(index, length, name, attributes[name]);
});
this.formatAt(index, length, attributes);
return index + length;
}, index);
}
Expand Down

0 comments on commit 0877563

Please sign in to comment.