Re-focus input bar on syntax error

This commit is contained in:
Arne Keller 2021-03-08 20:47:39 +01:00
parent cd5213a929
commit 9c8897d436
2 changed files with 7 additions and 1 deletions

View File

@ -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<TypeInfererInterface, ParseError> 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());
}

View File

@ -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";