Search in sources :

Example 36 with Range

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);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SpellCheckerResult(org.rstudio.studio.client.common.spelling.model.SpellCheckerResult) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 37 with Range

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;
}
Also used : Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Aggregations

Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)37 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)11 JsArrayString (com.google.gwt.core.client.JsArrayString)7 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)7 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)5 Token (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Token)5 ArrayList (java.util.ArrayList)4 AnchoredRange (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange)4 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)3 JsArray (com.google.gwt.core.client.JsArray)2 Command (com.google.gwt.user.client.Command)2 NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)2 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 Match (org.rstudio.core.client.regex.Match)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)2 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)2