From 9401ae876bd76ca6b2afb7753d6f48393a89e86f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 11 Oct 2021 21:11:28 -0400 Subject: [PATCH] Changeset: Sort attributes by keys, not full string rep --- src/static/js/Changeset.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index e70966d5f..78d5d3edc 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -1089,6 +1089,15 @@ exports.mutateTextLines = (cs, lines) => { mut.close(); }; +/** + * Sorts an array of attributes by key. + * + * @param {Attribute[]} attribs - The array of attributes to sort in place. + * @returns {Attribute[]} The `attribs` array. + */ +const sortAttribs = + (attribs) => attribs.sort((a, b) => (a[0] > b[0] ? 1 : 0) - (a[0] < b[0] ? 1 : 0)); + /** * Composes two attribute strings (see below) into one. * @@ -1144,9 +1153,8 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => { } return ''; }); - atts.sort(); const buf = exports.stringAssembler(); - for (const att of atts) { + for (const att of sortAttribs(atts)) { buf.append('*'); buf.append(exports.numToString(pool.putAttrib(att))); } @@ -1900,7 +1908,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => { } else if (pool && attribs.length) { if (attribs.length > 1) { attribs = attribs.slice(); - attribs.sort(); + sortAttribs(attribs); } const result = []; for (const pair of attribs) {