Page 1 of 1

[2.0.76] Strings containing rich text icons are sorted incorrectly in English and non-English localisations

Posted: Tue Mar 03, 2026 2:57 pm
by Sachertorte
I propose that the default sort order of rich text icons is incorrect in, separately, both English and non-English localisations. I suggested this (viewtopic.php?t=97719) 5 years ago and as time goes on I am more convinced that the current ordering is a detriment to the player's experience.

This negatively affects the game any time a list of custom strings is presented in a sorted order - for example, when selecting a train stop destination from a dropdown, or when space platforms are listed in the map view, as well as any lists added by mods. This is particularly impactful when using the wildcard modifier in train stop names (https://factorio.com/blog/post/fff-395) as that pretty much requires defining those names around the icon.
English
Which of the following icon orderings feels more correct?

Number 1:

ImageImageImageImageImageImageImageImageImageImageImageImageImage

Number 2:

ImageImageImageImageImageImageImageImageImageImageImageImageImage

Number 1 is the current in-game sort order of rich text icons. When rich text strings are sorted, the rich text is not processed specially at all, it's just treated as e.g. "[item=iron-plate]". The resulting sort order is effectively the result of sorting the items alphabetically by their internal ID. The same applies to different kinds of icons, e.g. achievements are sorted before fluids are sorted before items are sorted before technologies.

Number 2 is the current in-game sort order of icons in pretty much every other circumstance, e.g. in the inventory, crafting menu, factoriopedia, signal picker. IMO it fundamentally makes sense that all icons should always be ordered this way, and IMO it is a bug that they are not.

It is at least consistent in that the items are alphabetised by item ID. Except...
Non-English
The current rich text icon sort cannot ever make sense in any language other than English, because the IDs are in English. In other languages the order is nonsensical and arbitrary. The order is objectively incorrect.

And that only applies to base Factorio IDs. Modded IDs could be in any language the mod developer chooses, and sorted inconsistently as a result.
Solution
Using the inventory's sort order to sort rich text is trivial. I proved this with a now-outdated proof-of-concept mod that adds an intuitively-sorted list of train stops to the locomotive UI: https://mods.factorio.com/mod/ordered-r ... rain-stops

The procedure I used was:
  1. Before sorting, extract from the string all substrings that look like rich text icons ("%[([a-z]+)=(.-)%]") to get the prototype name and the entity ID (e.g. prototype=item, entity=iron-plate)
  2. For each substring, look up that entity ID in the corresponding prototype to get the entity
  3. Concatenate that entity's order properties (which determine its placement in the inventory list) to create a string (e.g. entity.group.order + entity.subgroup.order + entity.order)
  4. Substitute that string back into the original string in place of the rich text
  5. Proceed with the sort
Lua source code: https://github.com/rossjrw/factorio-ord ... t-sort.lua

entity.order makes sure icons are sorted within their groups, entity.subgroup.order makes sure entities are ordered by which inventory row they appear in, entity.group.order makes sure entities are ordered by which inventory tab they appear in. I don't think each set of prototypes has a defined order but I also don't think they're often mixed so it's probably fine.

This is localisation-agnostic as it uses the ordering properties that already exist and that are consistent in all localisations.

I did not notice any performance impact from this at all, however, I only tried adding 1 extra sorted list and Lua cannot modify all lists in the game as I am proposing.
Related bug reports
  • [0.18.10] Rich text train station names are not searchable: This is a bug report about a user failing to find a string that contained rich text in a search because they didn't know they had to search for the item ID. This could in theory be solved by, similar to my proposed solution above, replacing (or extending) strings that contain rich text with the localised name of the represented entity (e.g. search in a list that contains "[item=iron-plate]", and what is actually searched behind the scenes is "[item=iron-plate]Iron plate"). Otherwise the bug report is not related.
  • [0.17.39] Mods with icon beside their name not sorted correctly: I don't think this is relevant because the rich text icon is at the end of the mod name, not the start, so it shouldn't have affected the sort order? I don't think it's related. Regardless, the response to that thread was quite abrasive towards mod developers choosing to put icons in their mod names, but this bug report is about icons in ALL sorted lists, which is an intentional game feature (FFF-395).

Re: [2.0.76] Strings containing rich text icons are sorted incorrectly in English and non-English localisations

Posted: Tue Mar 03, 2026 4:38 pm
by Loewchen
That is a feature request and you already made it.

Re: [2.0.76] Strings containing rich text icons are sorted incorrectly in English and non-English localisations

Posted: Tue Mar 03, 2026 4:53 pm
by Sachertorte
Loewchen wrote: Tue Mar 03, 2026 4:38 pm That is a feature request and you already made it.
Having had this in the back of my head for 5 years now I don't agree with this. Or, I agree in the sense that "please fix this problem" is a feature request. I come back to this every time I have to look through my list of train stops that's sorted differently to everything else - I can't not see it as a bug any more.

Thank you for your response, but may I ask, would you have closed this bug report thread if I had not already made a feature request thread?

Re: [2.0.76] Strings containing rich text icons are sorted incorrectly in English and non-English localisations

Posted: Tue Mar 03, 2026 6:46 pm
by Rseding91
Yes, this is not a bug. We do not sort based off rich text rendering but always sort based off lexgographical ordering (sometimes ignoring case).

There are no plans to sort based off anything else.

Re: [2.0.76] Strings containing rich text icons are sorted incorrectly in English and non-English localisations

Posted: Wed Mar 04, 2026 12:41 am
by Sachertorte
Rseding91 wrote: Tue Mar 03, 2026 6:46 pm Yes, this is not a bug. We do not sort based off rich text rendering but always sort based off lexgographical ordering (sometimes ignoring case).

There are no plans to sort based off anything else.
Thanks for the response, I appreciate it. But I'll find a way to do this myself one way or another, even if it takes me another 5 years