package org.jabref.gui.fieldeditors;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import javafx.fxml.Initializable;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

import com.sun.javafx.scene.control.skin.TextAreaSkin;

public class EditorTextArea extends javafx.scene.control.TextArea implements Initializable {

    public EditorTextArea() {
        this("");
    }

    public EditorTextArea(String text) {
        super(text);

        setMinHeight(1);
        setMinWidth(200);

        // Hide horizontal scrollbar and always wrap text
        setWrapText(true);
    }

    /**
     * Adds the given list of menu items to the context menu.
     */
    public void addToContextMenu(List<MenuItem> items) {
        TextAreaSkin customContextSkin = new TextAreaSkin(this) {
            @Override
            public void populateContextMenu(ContextMenu contextMenu) {
                super.populateContextMenu(contextMenu);
                contextMenu.getItems().addAll(0, items);
            }
        };
        setSkin(customContextSkin);
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}

@@ -221,16 +221,87 @@
 enuItem;
+%0Aimport javafx.scene.input.KeyCode;%0Aimport javafx.scene.input.KeyEvent;
 %0A%0Aimport
@@ -698,16 +698,849 @@
 t(true);
+%0A%0A        // Should behave as a normal text field with respect to TAB behaviour%0A        addEventFilter(KeyEvent.KEY_PRESSED, event -%3E %7B%0A            if (event.getCode() == KeyCode.TAB) %7B%0A                TextAreaSkin skin = (TextAreaSkin) getSkin();%0A                if (event.isShiftDown()) %7B%0A                    // Shift + Tab %3E previous text area%0A                    skin.getBehavior().traversePrevious();%0A                %7D else %7B%0A                    if (event.isControlDown()) %7B%0A                        // Ctrl + Tab %3E insert tab%0A                        skin.getBehavior().callAction(%22InsertTab%22);%0A                    %7D else %7B%0A                        // Tab %3E next text area%0A                        skin.getBehavior().traverseNext();%0A                    %7D%0A                %7D%0A                event.consume();%0A            %7D%0A        %7D);
 %0A    %7D%0A%0A

Fix #2902: Tab in entry editor moves to next text area