Hi Doma! This is the kind of thing that would be easy to do using the script Pins & Boxes (link here: https://aescripts.com/pins-and-boxes/ )
If you don’t want to buy a script, then a solution that could work would be to add this expression in the source text:
inputText = "Your full text here";
speed = 10; // Characters per second
visibleChars = Math.floor(time * speed);
inputText.substr(0, visibleChars);
And add a Null Object to follow the top-right corner of the text dynamically using SourceRectAtTime. Then, you can parent the colored box to the null. For example:
textRect = thisComp.layer("Text Layer").sourceRectAtTime();
textPos = thisComp.layer("Text Layer").transform.position;
[textPos[0] + textRect.width, textPos[1] - textRect.height];
This way, the null adjusts automatically as the text grows, and the colored box follows it smoothly. It keeps things simple and flexible.
I took the liberty of creating it to test it out and here’s the aep file for you.
Hope this helps!