diff --git a/src/main/java/edu/kit/typicalc/presenter/Presenter.java b/src/main/java/edu/kit/typicalc/presenter/Presenter.java index 45bc066..e74e533 100644 --- a/src/main/java/edu/kit/typicalc/presenter/Presenter.java +++ b/src/main/java/edu/kit/typicalc/presenter/Presenter.java @@ -8,6 +8,9 @@ import edu.kit.typicalc.util.Result; import edu.kit.typicalc.view.main.MainView; import edu.kit.typicalc.view.main.MainView.MainViewListener; +import java.util.Optional; + +import static edu.kit.typicalc.view.main.InputBar.ASS_INPUT_FIELD_ID; import static edu.kit.typicalc.view.main.InputBar.TERM_INPUT_FIELD_ID; /** @@ -33,10 +36,13 @@ public class Presenter implements MainViewListener { public void typeInferLambdaString(String lambdaTerm, String typeAssumptions) { Result result = model.getTypeInferer(lambdaTerm, typeAssumptions); if (result.isError()) { - view.displayError(result.unwrapError()); - // focus the input bar again + ParseError e = result.unwrapError(); + view.displayError(e); + // focus the corresponding input field + String inputFieldId = e.getErrorType().equals(Optional.of(ParseError.ErrorType.TERM_ERROR)) + ? TERM_INPUT_FIELD_ID : ASS_INPUT_FIELD_ID; UI.getCurrent().getPage().executeJs( - "setTimeout(() => document.getElementById('" + TERM_INPUT_FIELD_ID + "').focus(), 0)"); + "setTimeout(() => document.getElementById('" + inputFieldId + "').focus(), 0)"); } else { view.setTypeInferenceView(result.unwrap()); } diff --git a/src/main/java/edu/kit/typicalc/view/main/InputBar.java b/src/main/java/edu/kit/typicalc/view/main/InputBar.java index c5cbc7a..014bcff 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InputBar.java +++ b/src/main/java/edu/kit/typicalc/view/main/InputBar.java @@ -35,7 +35,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { private static final String EXAMPLE_BUTTON_ID = "exampleButton"; private static final String LAMBDA_BUTTON_ID = "lambdaButton"; private static final String QUANTIFIER_BUTTON_ID = "quantifier-button"; - private static final String ASS_INPUT_FIELD_ID = "ass-input-field"; + public static final String ASS_INPUT_FIELD_ID = "ass-input-field"; private static final short MAX_INPUT_LENGTH = 1000;