I think this is what you’re looking for:
https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/composer-editor.js#L159-L164
Every time the focusTarget value changes, this setFocus function is called.
focusTarget
setFocus