use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTarget method onGoToEndOfCurrentScope.
@Handler
void onGoToEndOfCurrentScope() {
docDisplay_.focus();
Scope scope = docDisplay_.getCurrentScope();
if (scope != null) {
Position end = scope.getEnd();
if (end != null) {
Position position = Position.create(end.getRow(), Math.max(0, end.getColumn() - 1));
docDisplay_.setCursorPosition(position);
}
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class NotebookQueueState method getNotebookExecRange.
private NotebookExecRange getNotebookExecRange(Scope scope, Range range) {
// convert range into character offsets
Position startPos = range.getStart();
Position endPos = range.getEnd();
int start = 0;
int end = 0;
int pos = 0;
for (int row = scope.getPreamble().getRow(); row < scope.getEnd().getRow(); row++) {
String line = docDisplay_.getLine(row);
for (int col = 0; col <= line.length(); col++) {
if (startPos.getRow() == row && startPos.getColumn() == col) {
start = pos;
} else if (endPos.getRow() == row && endPos.getColumn() == col) {
end = pos;
break;
}
pos++;
}
}
// the newline)
if (end == 0)
end = pos - 1;
return NotebookExecRange.create(start, end);
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class SetupChunkOptionsPopupPanel method findOptsChunk.
private Range findOptsChunk() {
TokenIterator iterator = display_.createTokenIterator(position_);
while (true) {
Token token = iterator.stepForward();
if (token == null)
break;
if (token.hasType("codeend"))
break;
Position startPos = iterator.getCurrentTokenPosition();
if (!token.getValue().equals("opts_chunk"))
continue;
Position knitrPrefixPos = findKnitrPrefix(iterator.clone());
if (knitrPrefixPos != null)
startPos = knitrPrefixPos;
token = iterator.stepForward();
if (!token.getValue().equals("$"))
continue;
token = iterator.stepForward();
if (!token.getValue().equals("set"))
continue;
token = iterator.stepForward();
if (!token.getValue().equals("("))
continue;
if (!iterator.fwdToMatchingToken())
continue;
token = iterator.stepForward();
Position endPos = iterator.getCurrentTokenPosition();
return Range.fromPoints(startPos, endPos);
}
return null;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTargetNotebook method onScopeTreeReady.
@Override
public void onScopeTreeReady(ScopeTreeReadyEvent event) {
Scope thisScope = event.getCurrentScope();
// initialization
if (lastStart_ == null && lastEnd_ == null) {
if (thisScope != null) {
lastStart_ = Position.create(thisScope.getBodyStart());
lastEnd_ = Position.create(thisScope.getEnd());
}
return;
}
// avoid it)
if (thisScope != null) {
Position thisStart = thisScope.getBodyStart();
Position thisEnd = thisScope.getEnd();
if (((lastStart_ == null && thisStart == null) || (lastStart_ != null && lastStart_.compareTo(thisStart) == 0)) && ((lastEnd_ == null && thisEnd == null) || (lastEnd_ != null && lastEnd_.compareTo(thisEnd) == 0))) {
return;
}
lastStart_ = Position.create(thisScope.getBodyStart());
lastEnd_ = Position.create(thisScope.getEnd());
} else {
lastStart_ = null;
lastEnd_ = null;
}
for (ChunkOutputUi output : outputs_.values()) {
Scope scope = output.getScope();
// remove the widget
if (scope == null || !scope.isChunk() || scope.getBodyStart() == null || scope.getEnd() == null || scope.getEnd().getRow() - output.getCurrentRow() > 1) {
events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), output.getChunkId(), "", 0, ChunkChangeEvent.CHANGE_REMOVE));
}
}
}
Aggregations