The whole block including the text_f could be lifted into a helper, it might be a little clearer then, but I probably wouldn't move just the active logic.