Focus on next cell in repeating group

I’m trying to create an app that let users write a screenplay, and I can’t figure out how to focus on an input element in the next cell of a repeating group.

Details: I have a repeating group that displays screenplay items in simple text form. Each item has an assigned Category, like Action, Character, Dialogue, etc. Also, each script item has an “Order” field, and they are displayed in ascending order by the “Order” field. That means the “Order” field data is the same as the index for each script item.

I’ve set it up so that each cell inside the repeating group has two items.

  1. An input that displays the current item, and it’s formatted based on the item’s category field. This was easy.

  2. An input for a new line that only displays when a user tabs away from the current item, which should allow them to begin typing for a new screenplay item. For example, if they have entered a character, but not dialogue, then when they click on the displayed character name and the hit tab, it opens the input where they can then enter the character’s dialogue.

So far, I’ve been able to accomplish this, but I’m having trouble with the next part. When entering a new screenplay item, I have it set to create a new thing (screenplay item) when the input value is changed, and then update the order number of all the items after it in the repeating group. So far so good. What I can’t figure out is how to then display and focus on the input element in the next cell of the repeating group, so that the user can keep adding new lines from there.

For example, if the 3rd cell says “Steve”, and the user tabs from it, enters his dialogue line in the input, and hits tab to create the new thing, it’s still focused on the input in the 3rd cell, so the new dialogue is now displaying after the focused input. I want to focus on the next cell’s input, so that it’s after the new dialogue line they entered.

Hopefully, this novel makes sense.