expand "\r" treatment on to the previous lines in document to fix IDEA-170961 sys.stdout is severly damaged and does not execute '\r' correctly

This commit is contained in:
Alexey Kudravtsev
2017-04-05 16:42:15 +03:00
parent 915b22f2bf
commit 6580fbecda
3 changed files with 19 additions and 8 deletions
@@ -685,7 +685,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
int startIndex = startsWithCR ? 1 : 0;
for (int i = startIndex; i < deferredTokens.size(); i++) {
TokenBuffer.TokenInfo deferredToken = deferredTokens.get(i);
addedText.append(deferredToken.getText());
addedText.append(deferredToken.getText()); // can just append texts because \r inside these tokens were already taken care of
}
if (startsWithCR) {
// remove last line if any
@@ -65,13 +65,8 @@ class TokenBuffer {
TokenInfo tokenInfo = new TokenInfo(contentType, text.substring(start, crIndex), info);
tokens.addLast(tokenInfo);
size += tokenInfo.length();
removeLastLine();
}
else if (size == 0) {
// \r at the very beginning. return CR_TOKEN to signal this
tokens.addLast(CR_TOKEN);
size ++;
}
removeLastLine();
// text[start..crIndex) should be removed
start = crIndex + 1;
}
@@ -110,10 +105,16 @@ class TokenBuffer {
TokenInfo newToken = new TokenInfo(last.contentType, text.substring(0, lfIndex + 1), last.getHyperlinkInfo());
tokens.addLast(newToken);
size -= text.length() - newToken.length();
break;
return;
}
// remove the token entirely, move to the previous
size -= text.length();
}
if (tokens.isEmpty()) {
// \r at the very beginning. return CR_TOKEN to signal this
tokens.addLast(CR_TOKEN);
size ++;
}
}
private void trim() {
@@ -374,4 +374,14 @@ public class ConsoleViewImplTest extends LightPlatformTestCase {
() -> EditorTestUtil.executeAction(editor, true, handler),
"", null, editor.getDocument());
}
public void testCRPrintCR() throws Exception {
for (int i=0;i<25;i++) {
myConsole.print("\r"+i, ConsoleViewContentType.NORMAL_OUTPUT);
Thread.sleep(100);
}
myConsole.flushDeferredText();
myConsole.waitAllRequests();
assertEquals("24", myConsole.getText());
}
}