IDEA-57708 Version control console: caret moved from the last position could be kept...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 12:46:21 +0000 (16:46 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 12:47:26 +0000 (16:47 +0400)
Add a flag to EditorAdapter to make scrolling to the end optional.

platform/platform-api/src/com/intellij/util/ui/EditorAdapter.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java
plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvshandlers/CvsMessagesConsole.java

index f42d79e707acb3be00ce6bce50f4b412d9d9e203..7080e9595fc41291e2a52f7fd6269bcb9d08676b 100644 (file)
@@ -58,6 +58,7 @@ public class EditorAdapter {
   private final Alarm myFlushAlarm = new Alarm();
   private final Collection<Line> myLines = new ArrayList<Line>();
   private final Project myProject;
+  private final boolean myScrollToTheEndOnAppend;
 
   private final Runnable myFlushDeferredRunnable = new Runnable() {
     public void run() {
@@ -75,9 +76,10 @@ public class EditorAdapter {
   }
 
 
-  public EditorAdapter(Editor editor, Project project) {
+  public EditorAdapter(Editor editor, Project project, boolean scrollToTheEndOnAppend) {
     myEditor = editor;
     myProject = project;
+    myScrollToTheEndOnAppend = scrollToTheEndOnAppend;
     LOG.assertTrue(myEditor.isViewer());
   }
 
@@ -126,8 +128,10 @@ public class EditorAdapter {
   }
 
   private void shiftCursorToTheEndOfDocument() {
-    myEditor.getCaretModel().moveToOffset(myEditor.getDocument().getTextLength());
-    myEditor.getSelectionModel().removeSelection();
-    myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
+    if (myScrollToTheEndOnAppend) {
+      myEditor.getCaretModel().moveToOffset(myEditor.getDocument().getTextLength());
+      myEditor.getSelectionModel().removeSelection();
+      myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
+    }
   }
 }
index 7017c8539df02030696b8a5ff080eb8590ae7b47..9adc68d4fc314b2531143ff4a6710090603660db 100644 (file)
@@ -400,7 +400,7 @@ public void addMessageToConsoleWindow(final String message, final TextAttributes
       editorSettings.setFoldingOutlineShown(false);
 
       ((EditorImpl)editor).getScrollPane().setBorder(null);
-      myEditorAdapter = new EditorAdapter(editor, myProject);
+      myEditorAdapter = new EditorAdapter(editor, myProject, false);
       final JPanel panel = new JPanel(new BorderLayout());
       panel.add(editor.getComponent(), BorderLayout.CENTER);
 
index 5bea41886dcaa0aaf04262d40ae1fc3fb008cc52..d62ee03c2d297cea21cdc4c1d13964e8ed683b77 100644 (file)
@@ -36,7 +36,7 @@ public class CvsMessagesConsole extends CvsMessagesAdapter {
   public static final TextAttributes COMMAND = new TextAttributes(null, null, null, EffectType.LINE_UNDERSCORE, Font.BOLD);
 
   public void connectToOutputView(Editor editor, Project project) {
-    myOutput = new EditorAdapter(editor, project);
+    myOutput = new EditorAdapter(editor, project, true);
   }
 
   public void addMessage(final MessageEvent event) {