Fix unneeded recompilation causing loss of node focus
This commit is contained in:
@ -89,7 +89,13 @@ public class DesignerWindowPresenter {
|
||||
});
|
||||
|
||||
view.getRefreshASTButton().setOnAction(this::onRefreshASTClicked);
|
||||
view.sourceCodeProperty().addListener((observable, oldValue, newValue) -> view.notifyOutdatedAST());
|
||||
view.sourceCodeProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (model.isRecompilationNeeded(newValue)) {
|
||||
view.notifyOutdatedAST();
|
||||
} else {
|
||||
view.acknowledgeUpdatedAST();
|
||||
}
|
||||
});
|
||||
|
||||
onRefreshASTClicked(null); // Restore AST and XPath results
|
||||
}
|
||||
@ -205,7 +211,10 @@ public class DesignerWindowPresenter {
|
||||
|
||||
|
||||
private void onRefreshASTClicked(ActionEvent event) {
|
||||
refreshAST();
|
||||
String source = view.getCodeEditorArea().getText();
|
||||
if (model.isRecompilationNeeded(source)) {
|
||||
refreshAST(source);
|
||||
}
|
||||
if (StringUtils.isNotBlank(view.getXpathExpressionArea().getText())) {
|
||||
evaluateXPath();
|
||||
} else {
|
||||
@ -215,10 +224,10 @@ public class DesignerWindowPresenter {
|
||||
|
||||
|
||||
/** Refresh the AST view with the updated code. */
|
||||
private void refreshAST() {
|
||||
private void refreshAST(String source) {
|
||||
Node n = null;
|
||||
try {
|
||||
n = model.getCompilationUnit(view.getCodeEditorArea().getText());
|
||||
n = model.getCompilationUnit(source);
|
||||
} catch (ParseTimeException e) {
|
||||
notifyParseTimeException(e);
|
||||
}
|
||||
|
@ -97,9 +97,17 @@ public class ASTManager {
|
||||
}
|
||||
|
||||
|
||||
public boolean isRecompilationNeeded(String source) {
|
||||
return !StringUtils.equals(source, lastValidSource)
|
||||
|| !languageVersion.get().equals(lastLanguageVersion);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refreshes the compilation unit given the current parameters of the model.
|
||||
*
|
||||
* @param source Source code
|
||||
*
|
||||
* @throws ParseTimeException if parsing or one of the visitors fails. The cause is preserved.
|
||||
*/
|
||||
public Node getCompilationUnit(String source) throws ParseTimeException {
|
||||
|
Reference in New Issue
Block a user