well to start off theres an abstract Material class with several implementations, all of them, except for ElementaryMaterial, store one or more materials inside of the - basically forming a tree structure.
custom classes for FormattedCharSequence (this interface iterates over every character) and FormattedCharSink (this interface decides what to do with every character) are made that take in an additional Material parameter [1].
there are static methods that return the MaterialCharSequence for each of the different Material classes, they iterate over the MaterialCharSequences of the inner materials in the tree and decide when or when not to parenthesise [2].
to make sure that the whole inside of the parentheses is highlighted, a custom sink accepts a constant material instead of passing the actual material used for adding the text [3].
with a mixin, i freeze the tooltip and hovered slot whenever alt is held, i also add the material tooltip to the list of tooltips and find the mouse's position on the tooltip [4]. a mixin to StringSplitter lets me find the compound the mouse is hovering [4] over and a custom ClientMaterialTooltip [5] class (and another mixin) tells the text renderer to change the style and render the glow when the text comes from the hovered material [6]. if the mouse was clicked, i store the hovered material and use it instead of the vanilla tooltip [4].