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

3 comments
Comment actions Permalink
Official comment

You can call directly the API that NextVariableAction does:

TemplateManagerImpl.getTemplateState(editor).nextTab();

Comment actions Permalink

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
Comment actions Permalink

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 :)

0

Please sign in to leave a comment.