From 9c8897d436f7a6d595c1352bb7c0180b6d579802 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Mon, 8 Mar 2021 20:47:39 +0100 Subject: [PATCH] Re-focus input bar on syntax error --- src/main/java/edu/kit/typicalc/presenter/Presenter.java | 6 ++++++ src/main/java/edu/kit/typicalc/view/main/InputBar.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/kit/typicalc/presenter/Presenter.java b/src/main/java/edu/kit/typicalc/presenter/Presenter.java index 22d6065..31ecb9c 100644 --- a/src/main/java/edu/kit/typicalc/presenter/Presenter.java +++ b/src/main/java/edu/kit/typicalc/presenter/Presenter.java @@ -2,6 +2,7 @@ package edu.kit.typicalc.presenter; import java.util.Map; +import com.vaadin.flow.component.UI; import edu.kit.typicalc.model.Model; import edu.kit.typicalc.model.TypeInfererInterface; import edu.kit.typicalc.model.parser.ParseError; @@ -9,6 +10,8 @@ import edu.kit.typicalc.util.Result; import edu.kit.typicalc.view.main.MainView; import edu.kit.typicalc.view.main.MainView.MainViewListener; +import static edu.kit.typicalc.view.main.InputBar.INPUT_FIELD_ID; + /** * Manages data exchange between the view and the model. */ @@ -33,6 +36,9 @@ public class Presenter implements MainViewListener { Result result = model.getTypeInferer(lambdaTerm, typeAssumptions); if (result.isError()) { view.displayError(result.unwrapError()); + // focus the input bar again + UI.getCurrent().getPage().executeJs( + "setTimeout(() => document.getElementById('" + INPUT_FIELD_ID + "').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 1fc9135..c3f785c 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InputBar.java +++ b/src/main/java/edu/kit/typicalc/view/main/InputBar.java @@ -29,7 +29,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { /* * IDs for the imported .css-file */ - private static final String INPUT_FIELD_ID = "inputField"; + public static final String INPUT_FIELD_ID = "inputField"; private static final String INPUT_BAR_ID = "inputBar"; private static final String INFER_BUTTON_ID = "inferButton"; private static final String EXAMPLE_BUTTON_ID = "exampleButton";