diff --git a/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java b/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java index e10cdce82b0..2c618816741 100644 --- a/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java +++ b/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java @@ -1597,21 +1597,28 @@ void onInsertChunk() @Handler void onExecuteCurrentChunk() { - executeSweaveChunk(scopeHelper_.getCurrentSweaveChunk()); + executeSweaveChunk(scopeHelper_.getCurrentSweaveChunk(), false); } @Handler void onExecuteNextChunk() { - executeSweaveChunk(scopeHelper_.getNextSweaveChunk()); + executeSweaveChunk(scopeHelper_.getNextSweaveChunk(), true); } - private void executeSweaveChunk(Scope chunk) + private void executeSweaveChunk(Scope chunk, boolean scrollNearTop) { if (chunk == null) return; Range range = scopeHelper_.getSweaveChunkInnerRange(chunk); + if (scrollNearTop) + { + docDisplay_.navigateToPosition( + SourcePosition.create(range.getStart().getRow(), + range.getStart().getColumn()), + true); + } docDisplay_.setSelection( docDisplay_.createSelection(range.getStart(), range.getEnd())); if (!range.isEmpty())