Focus correct input field on syntax error

fixes #11
This commit is contained in:
Arne Keller 2021-07-12 10:09:20 +02:00
parent ca2ea6c277
commit b0288a1e3e
2 changed files with 10 additions and 4 deletions

View File

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

View File

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