IDEA-71147 Automatically 'scroll to the end'

Scrolling to the console end in case long soft wrapped lines were added while the console was not showing.
This commit is contained in:
Denis Zhdanov
2011-06-23 17:00:51 +04:00
parent 98f71f261c
commit 2db49ea860
@@ -39,10 +39,7 @@ import com.intellij.openapi.editor.actionSystem.*;
import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
import com.intellij.openapi.editor.actions.ToggleUseSoftWrapsToolbarAction;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.editor.event.EditorMouseEvent;
import com.intellij.openapi.editor.event.*;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
@@ -403,6 +400,25 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
}
});
myEditor.getScrollingModel().addVisibleAreaListener(new VisibleAreaListener() {
@Override
public void visibleAreaChanged(VisibleAreaEvent e) {
// There is a possible case that the console text is populated while the console is not shown (e.g. we're debugging and
// 'Debugger' tab is active while 'Console' is not). It's also possible that newly added text contains long lines that
// are soft wrapped. We want to update viewport position then when the console becomes visible.
final Rectangle oldRectangle = e.getOldRectangle();
final Rectangle newRectangle = e.getNewRectangle();
if (oldRectangle == null || newRectangle == null) {
return;
}
if (oldRectangle.height <= 0 && newRectangle.height > 0 && myEditor.getSoftWrapModel().isSoftWrappingEnabled()
&& myEditor.getCaretModel().getOffset() == myEditor.getDocument().getTextLength()) {
EditorUtil.scrollToTheEnd(myEditor);
}
}
});
}
return this;
}