Fixed exception in ConsoleViewImpl on typing immediately after multiple \r

This commit is contained in:
Vyacheslav Karpukhin
2015-05-22 20:02:12 +02:00
parent a3eb82d71d
commit 9124f312fd
2 changed files with 27 additions and 1 deletions
@@ -709,7 +709,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
try {
myInDocumentUpdate = true;
String[] strings = addedText.split("\\r");
String[] strings = addedText.split("\\r", -1);
for (int i = 0; i < strings.length - 1; i++) {
document.insertString(document.getTextLength(), strings[i]);
int lastLine = document.getLineCount() - 1;
@@ -17,10 +17,14 @@ package com.intellij.execution.impl;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.editor.actionSystem.TypedAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.TestDataProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -45,6 +49,28 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
}
}
public void testTypingAfterMultipleCR() throws Exception {
final EditorActionManager actionManager = EditorActionManager.getInstance();
final TypedAction typedAction = actionManager.getTypedAction();
final TestDataProvider dataContext = new TestDataProvider(getProject());
final ConsoleViewImpl console = createConsole();
final Editor editor = console.getEditor();
try {
console.print("System output\n", ConsoleViewContentType.SYSTEM_OUTPUT);
console.print("\r\r\r\r\r\r\r", ConsoleViewContentType.NORMAL_OUTPUT);
console.flushDeferredText();
typedAction.actionPerformed(editor, '1', dataContext);
typedAction.actionPerformed(editor, '2', dataContext);
assertEquals("System output\n12", editor.getDocument().getText());
}
finally {
Disposer.dispose(console);
}
}
@NotNull
private static ConsoleViewImpl createConsole() {
Project project = getProject();