Skip to content

Commit fe07527

Browse files
committed
Changeset: Sort attributes by keys, not full string rep
1 parent 3e4af64 commit fe07527

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/static/js/Changeset.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,15 @@ exports.mutateTextLines = (cs, lines) => {
10891089
mut.close();
10901090
};
10911091

1092+
/**
1093+
* Sorts an array of attributes by key.
1094+
*
1095+
* @param {Attribute[]} attribs - The array of attributes to sort in place.
1096+
* @returns {Attribute[]} The `attribs` array.
1097+
*/
1098+
const sortAttribs =
1099+
(attribs) => attribs.sort((a, b) => (a[0] > b[0] ? 1 : 0) - (a[0] < b[0] ? 1 : 0));
1100+
10921101
/**
10931102
* Composes two attribute strings (see below) into one.
10941103
*
@@ -1144,9 +1153,8 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
11441153
}
11451154
return '';
11461155
});
1147-
atts.sort();
11481156
const buf = exports.stringAssembler();
1149-
for (const att of atts) {
1157+
for (const att of sortAttribs(atts)) {
11501158
buf.append('*');
11511159
buf.append(exports.numToString(pool.putAttrib(att)));
11521160
}
@@ -1900,7 +1908,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
19001908
} else if (pool && attribs.length) {
19011909
if (attribs.length > 1) {
19021910
attribs = attribs.slice();
1903-
attribs.sort();
1911+
sortAttribs(attribs);
19041912
}
19051913
const result = [];
19061914
for (const pair of attribs) {

0 commit comments

Comments
 (0)