package com.karateca.jstoolbox.toconstructor;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.karateca.jstoolbox.MyAction;

/**
 * @author Andres Dominguez.
 */
public class GoToConstructorAction extends MyAction {

  public void actionPerformed(AnActionEvent actionEvent) {
    Editor editor = actionEvent.getData(PlatformDataKeys.EDITOR);
    if (editor == null) {
      return;
    }

    Document document = editor.getDocument();

    String text = document.getText();

    // Find the @constructor and then go to the first function.
    int offset = text.indexOf("@constructor");
    offset = text.indexOf("function", offset);

    editor.getCaretModel().moveToOffset(offset);
  }
}

@@ -243,16 +243,63 @@
 Editor;%0A
+import com.intellij.openapi.editor.ScrollType;%0A
 import c
@@ -889,14 +889,79 @@
 ffset);%0A
+    editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);%0A
   %7D%0A%7D%0A

Add scroll to caret