use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class CheckSpelling method handleMisspelledWord.
private void handleMisspelledWord(Range range) {
try {
docDisplay_.setSelectionRange(range);
docDisplay_.moveCursorNearTop();
view_.clearSuggestions();
view_.getReplacement().setText("");
final String word = docDisplay_.getTextForRange(range);
if (changeAll_.containsKey(word)) {
doReplacement(changeAll_.get(word));
findNextMisspelling();
return;
}
view_.getMisspelledWord().setText(word);
// This fixed delay is regrettable but necessary as it can take some
// time for Ace's scrolling logic to actually execute (i.e. the next
// time the renderloop runs). If we don't wait, then misspelled words
// at the end of the document will result in misreported cursor bounds,
// meaning we'll be avoiding a completely incorrect region.
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
showDialog(docDisplay_.getCursorBounds());
view_.focusReplacement();
spellChecker_.suggestionList(word, new ServerRequestCallback<JsArrayString>() {
@Override
public void onResponseReceived(JsArrayString response) {
String[] suggestions = JsUtil.toStringArray(response);
view_.setSuggestions(suggestions);
if (suggestions.length > 0) {
view_.getReplacement().setText(suggestions[0]);
view_.focusReplacement();
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
return false;
}
}, 100);
} catch (Exception e) {
Debug.log(e.toString());
close();
RStudioGinjector.INSTANCE.getGlobalDisplay().showErrorMessage("Check Spelling", "An error has occurred:\n\n" + e.getMessage());
callback_.onFailure(e);
}
}
Aggregations