Advance Live Template programmatically

Answered

Hi there,

Which API can I use to move to the next live template variable within an editor? I'm looking to mimic the behavior for when someone presses "enter" when finished typing in those red boxes that popup when a live template is invoked. It is also the same behavior when tab is pressed

1
6 comments
Official comment

You can call directly the API that NextVariableAction does:

TemplateManagerImpl.getTemplateState(editor).nextTab();

I'm assuming I have to use:

ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE).actionPerformed(AnActionEvent.createFromAnAction(???));


Just not sure what to plug into createFromAction()

0

I got the behavior I desired to work with this verbose code.

AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE);
ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE).actionPerformed
(AnActionEvent.createFromAnAction(action,null,ActionPlaces.UNKNOWN, DataManager.getInstance().getDataContext(event.getLookup().getEditor().getComponent())));


If there's a better looking way, please let me know :)

1

Hi, sorry for bringing back this post. Is there a way to bring back the live template mode after clicking out of it. So i am able to tab through the variables again like in live template mode?

0

No, unfortunately that's complicated. One has to create a new live template that behaves just like the old one, and AFAIK there's no code doing that yet.

0

I see, i was hoping that feature existed. Thanks for the fast reply. 

0

Please sign in to leave a comment.