package me.coley.recaf.ui.controls.text;

import javafx.scene.Node;
import javafx.scene.control.ListCell;
import javafx.scene.text.Text;
import me.coley.recaf.util.struct.Pair;
import org.fxmisc.richtext.CodeArea;

/**
 * Cell renderer.
 *
 * @author Matt
 */
public class ErrorCell extends ListCell<Pair<Integer, String>> {
	private final CodeArea codeArea;

	/**
	 * @param codeArea
	 * 		Code area containing the text with errors.
	 */
	public ErrorCell(CodeArea codeArea) {
		this.codeArea = codeArea;
	}

	@Override
	public void updateItem(Pair<Integer, String> item, boolean empty) {
		super.updateItem(item, empty);
		if(empty) {
			setText(null);
			setGraphic(null);
		} else {
			setText(item.getValue());
			int index = item.getKey();
			Node g = new Text(String.valueOf(index + 1));
			g.getStyleClass().addAll("bold", "error-cell");
			setGraphic(g);
			// on-click: go to line
			setOnMouseClicked(me -> {
				codeArea.moveTo(index, 0);
				codeArea.requestFollowCaret();
				codeArea.requestFocus();
			});
		}
	}
}

@@ -884,16 +884,37 @@
 to line%0A
+%09%09%09if(index %3E= 0) %7B%0A%09
 %09%09%09setOn
@@ -934,24 +934,25 @@
 me -%3E %7B%0A%09%09%09%09
+%09
 codeArea.mov
@@ -966,16 +966,17 @@
 ex, 0);%0A
+%09
 %09%09%09%09code
@@ -1002,24 +1002,25 @@
 aret();%0A%09%09%09%09
+%09
 codeArea.req
@@ -1036,15 +1036,103 @@
 ();%0A
+%09
 %09%09%09%7D);%0A
+%09%09%09%7D else %7B%0A%09%09%09%09setText(getText() + %22%5Cn(Cannot resolve line number from error)%22);%0A%09%09%09%7D%0A
 %09%09%7D%0A

Fix non-resolved errors throwing errors on click