Search in sources :

Example 1 with ScopePredicate

use of org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate in project rstudio by rstudio.

the class TextEditingTargetScopeHelper method getSweaveChunks.

public Scope[] getSweaveChunks(Position startPosition, final int which) {
    // provide default position based on selection if necessary
    final Position position = startPosition != null ? startPosition : docDisplay_.getSelectionStart();
    ScopeList scopeList = new ScopeList(docDisplay_);
    scopeList.selectAll(ScopeList.CHUNK);
    scopeList.selectAll(new ScopePredicate() {

        @Override
        public boolean test(Scope scope) {
            if (!scope.isChunk())
                return false;
            int dir = scope.getEnd().compareTo(position);
            if (which == PREVIOUS_CHUNKS)
                return dir < 0;
            else
                return dir > 0;
        }
    });
    return scopeList.getScopes();
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) ScopePredicate(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate)

Example 2 with ScopePredicate

use of org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate in project rstudio by rstudio.

the class TextEditingTargetScopeHelper method getNextSweaveChunk.

public Scope getNextSweaveChunk() {
    ScopeList scopeList = new ScopeList(docDisplay_);
    scopeList.selectAll(ScopeList.CHUNK);
    final Position selectionEnd = docDisplay_.getSelectionEnd();
    return scopeList.findFirst(new ScopePredicate() {

        @Override
        public boolean test(Scope scope) {
            return scope.getPreamble().compareTo(selectionEnd) > 0;
        }
    });
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) ScopePredicate(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate)

Example 3 with ScopePredicate

use of org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate in project rstudio by rstudio.

the class TextEditingTargetScopeHelper method getNextFunction.

public Scope getNextFunction(final Position position) {
    ScopeList scopeList = new ScopeList(docDisplay_);
    scopeList.selectAll(ScopeList.FUNC);
    return scopeList.findFirst(new ScopePredicate() {

        @Override
        public boolean test(Scope scope) {
            return scope.getPreamble().compareTo(position) > 0;
        }
    });
}
Also used : ScopePredicate(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate)

Example 4 with ScopePredicate

use of org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate in project rstudio by rstudio.

the class TextEditingTargetScopeHelper method getPreviousFunction.

public Scope getPreviousFunction(final Position position) {
    ScopeList scopeList = new ScopeList(docDisplay_);
    scopeList.selectAll(ScopeList.FUNC);
    return scopeList.findLast(new ScopePredicate() {

        @Override
        public boolean test(Scope scope) {
            return scope.getPreamble().compareTo(position) < 0;
        }
    });
}
Also used : ScopePredicate(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate)

Aggregations

ScopePredicate (org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList.ScopePredicate)4 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)2