Skip to content

Commit ba7bfa8

Browse files
committed
Changeset: Sort attributes by keys, not full string rep
1 parent 49f4abf commit ba7bfa8

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
@@ -1087,6 +1087,15 @@ exports.mutateTextLines = (cs, lines) => {
10871087
mut.close();
10881088
};
10891089

1090+
/**
1091+
* Sorts an array of attributes by key.
1092+
*
1093+
* @param {Attribute[]} attribs - The array of attributes to sort in place.
1094+
* @returns {Attribute[]} The `attribs` array.
1095+
*/
1096+
const sortAttribs =
1097+
(attribs) => attribs.sort((a, b) => (a[0] > b[0] ? 1 : 0) - (a[0] < b[0] ? 1 : 0));
1098+
10901099
/**
10911100
* Composes two attribute strings (see below) into one.
10921101
*
@@ -1142,9 +1151,8 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
11421151
}
11431152
return '';
11441153
});
1145-
atts.sort();
11461154
const buf = exports.stringAssembler();
1147-
for (const att of atts) {
1155+
for (const att of sortAttribs(atts)) {
11481156
buf.append('*');
11491157
buf.append(exports.numToString(pool.putAttrib(att)));
11501158
}
@@ -1898,7 +1906,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
18981906
} else if (pool && attribs.length) {
18991907
if (attribs.length > 1) {
19001908
attribs = attribs.slice();
1901-
attribs.sort();
1909+
sortAttribs(attribs);
19021910
}
19031911
const result = [];
19041912
for (const pair of attribs) {

0 commit comments

Comments
 (0)