Permalink
Browse files

Simplify autoscroll implementation

Stops flashing in ShellWidget when lots of results are streaming back
  • Loading branch information...
1 parent a25cff1 commit 0de9b3ad00302cc203d8f0dc18276efb54e3f960 @jcheng5 jcheng5 committed Aug 17, 2012
@@ -12,14 +12,13 @@
*/
package org.rstudio.studio.client.common;
+import com.google.gwt.user.client.ui.Composite;
import org.rstudio.core.client.VirtualConsole;
+import org.rstudio.core.client.widget.BottomScrollPanel;
import org.rstudio.core.client.widget.FontSizer;
import org.rstudio.core.client.widget.PreWidget;
import org.rstudio.studio.client.workbench.views.console.ConsoleResources;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.ScrollPanel;
-
public class OutputBuffer extends Composite
{
public OutputBuffer()
@@ -29,7 +28,7 @@ public OutputBuffer()
ConsoleResources.INSTANCE.consoleStyles().output());
FontSizer.applyNormalFontSize(output_);
- scrollPanel_ = new ScrollPanel();
+ scrollPanel_ = new BottomScrollPanel();
scrollPanel_.setSize("100%", "100%");
scrollPanel_.add(output_);
@@ -38,14 +37,10 @@ public OutputBuffer()
public void append(String output)
{
- boolean isAtBottom = scrollPanel_.getVerticalScrollPosition() ==
- scrollPanel_.getMaximumVerticalScrollPosition();
-
virtualConsole_.submit(output);
output_.setText(virtualConsole_.toString());
-
- if (isAtBottom)
- scrollPanel_.scrollToBottom();
+
+ scrollPanel_.onContentSizeChanged();
}
public void scrollToBottom()
@@ -61,5 +56,5 @@ public void clear()
private PreWidget output_;
private VirtualConsole virtualConsole_ = new VirtualConsole();
- private ScrollPanel scrollPanel_;
+ private BottomScrollPanel scrollPanel_;
}
@@ -214,50 +214,22 @@ public void setSuppressPendingInput(boolean suppressPendingInput)
public void consoleWriteError(final String error)
{
- withAutoScroll(new Command() {
- @Override
- public void execute()
- {
- clearPendingInput();
- output(error, styles_.error(), false);
- }
- });
+ clearPendingInput();
+ output(error, styles_.error(), false);
}
public void consoleWriteOutput(final String output)
{
- withAutoScroll(new Command() {
- @Override
- public void execute()
- {
- clearPendingInput();
- output(output, styles_.output(), false);
- }
- });
+ clearPendingInput();
+ output(output, styles_.output(), false);
}
public void consoleWriteInput(final String input)
{
- withAutoScroll(new Command() {
- @Override
- public void execute()
- {
- clearPendingInput();
- output(input, styles_.command() + KEYWORD_CLASS_NAME, false);
- }
- });
+ clearPendingInput();
+ output(input, styles_.command() + KEYWORD_CLASS_NAME, false);
}
- private void withAutoScroll(Command command)
- {
- boolean isAtBottom = scrollPanel_.isScrolledToBottom();
-
- command.execute();
-
- if (isAtBottom)
- scrollToBottomCommand_.nudge();
- }
-
private void clearPendingInput()
{
pendingInput_.setText("");
@@ -266,13 +238,7 @@ private void clearPendingInput()
public void consoleWritePrompt(final String prompt)
{
- withAutoScroll(new Command() {
- @Override
- public void execute()
- {
- output(prompt, styles_.prompt() + KEYWORD_CLASS_NAME, false);
- }
- });
+ output(prompt, styles_.prompt() + KEYWORD_CLASS_NAME, false);
}
public void consolePrompt(String prompt, boolean showInput)
@@ -381,7 +347,13 @@ private boolean output(String text,
lines_ += DomUtils.countLines(node, true);
}
- return !trimExcess();
+ boolean result = !trimExcess();
+
+ scrollPanel_.onContentSizeChanged();
+ if (scrollPanel_.isScrolledToBottom())
+ scrollToBottomCommand_.nudge();
+
+ return result;
}
private String ensureNewLine(String s)

0 comments on commit 0de9b3a

Please sign in to comment.