use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class CheckSpelling method findNextMisspelling.
private void findNextMisspelling() {
try {
if (checkForCancel())
return;
showProgress();
Iterable<Range> wordSource = docDisplay_.getWords(docDisplay_.getFileType().getTokenPredicate(), docDisplay_.getFileType().getCharPredicate(), currentPos_, wrapped_ ? initialCursorPos_.getPosition() : null);
final ArrayList<String> words = new ArrayList<String>();
final ArrayList<Range> wordRanges = new ArrayList<Range>();
for (Range r : wordSource) {
// Don't worry about pathologically long words
if (r.getEnd().getColumn() - r.getStart().getColumn() > 250)
continue;
wordRanges.add(r);
words.add(docDisplay_.getTextForRange(r));
// Check a maximum of N words at a time
if (wordRanges.size() == 100)
break;
}
if (wordRanges.size() > 0) {
spellChecker_.checkSpelling(words, new SimpleRequestCallback<SpellCheckerResult>() {
@Override
public void onResponseReceived(SpellCheckerResult response) {
if (checkForCancel())
return;
for (int i = 0; i < words.size(); i++) {
if (response.getIncorrect().contains(words.get(i))) {
handleMisspelledWord(wordRanges.get(i));
return;
}
}
currentPos_ = wordRanges.get(wordRanges.size() - 1).getEnd();
// Everything spelled correctly, continue
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
findNextMisspelling();
}
});
}
});
} else {
// No misspellings
if (wrapped_) {
close();
RStudioGinjector.INSTANCE.getGlobalDisplay().showMessage(GlobalDisplay.MSG_INFO, "Check Spelling", "Spell check is complete.");
callback_.onSuccess(Void.create());
} else {
wrapped_ = true;
currentPos_ = Position.create(0, 0);
findNextMisspelling();
}
}
} 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);
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class TextEditingTargetNotebook method needsSetupChunkExecuted.
private boolean needsSetupChunkExecuted() {
// ignore if disabled
if (!prefs_.autoRunSetupChunk().getValue())
return false;
// queue
if (queue_.isChunkExecuting(SETUP_CHUNK_ID) || queue_.isChunkQueued(SETUP_CHUNK_ID)) {
return false;
}
// no reason to do work if we don't need to re-validate the setup chunk
if (!validateSetupChunk_ && !StringUtil.isNullOrEmpty(setupCrc32_))
return false;
validateSetupChunk_ = false;
// find the setup chunk
Scope setupScope = getSetupChunkScope();
if (setupScope != null) {
// make sure there's some code to execute
Range range = scopeHelper_.getSweaveChunkInnerRange(setupScope);
if (range.getStart().isEqualTo(range.getEnd()))
return false;
String crc32 = getChunkCrc32(setupScope);
// setup chunk
if (crc32 != setupCrc32_) {
// push it into the execution queue
return true;
}
}
return false;
}
Aggregations