From d04d4f7b38c846a42bfdf40b5a0d1bb53013da24 Mon Sep 17 00:00:00 2001 From: Elizaveta Shashkova Date: Thu, 27 Oct 2016 12:10:16 +0300 Subject: [PATCH] First line becomes hidden in the first cell of IPython console (PY-21248) Integrated and Debug console should remove folding after different number of commands executed, because debug console's start command is assumed as a command executed in console. --- .../python/console/PyConsoleStartFolding.java | 24 ++++++++++++------- .../python/console/PythonConsoleView.java | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java b/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java index 289fcdbd7c82..afc03dac4002 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java +++ b/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java @@ -27,11 +27,12 @@ import org.jetbrains.annotations.NotNull; public class PyConsoleStartFolding extends DocumentAdapter implements ConsoleCommunicationListener, FoldingListener { private PythonConsoleView myConsoleView; - private boolean isFirstCommandWasExecuted = false; + private int myNumberOfCommandExecuted = 0; + private int myNumberOfCommandToStop = 1; private boolean doNotAddFoldingAgain = false; private FoldRegion myStartFoldRegion; private static final String DEFAULT_FOLDING_MESSAGE = "Python Console"; - private int startLineOffset = 0; + private int myStartLineOffset = 0; public PyConsoleStartFolding(PythonConsoleView consoleView) { super(); @@ -39,7 +40,11 @@ public class PyConsoleStartFolding extends DocumentAdapter implements ConsoleCom } public void setStartLineOffset(int startLineOffset) { - this.startLineOffset = startLineOffset; + myStartLineOffset = startLineOffset; + } + + public void setNumberOfCommandToStop(int numberOfCommandToStop) { + myNumberOfCommandToStop = numberOfCommandToStop; } @Override @@ -52,11 +57,15 @@ public class PyConsoleStartFolding extends DocumentAdapter implements ConsoleCom if (doNotAddFoldingAgain || document.getTextLength() == 0) { return; } + if (myNumberOfCommandExecuted >= myNumberOfCommandToStop) { + document.removeDocumentListener(this); + return; + } FoldingModel foldingModel = myConsoleView.getEditor().getFoldingModel(); foldingModel.runBatchFoldingOperation(() -> { - int start = startLineOffset; + int start = myStartLineOffset; String placeholderText = DEFAULT_FOLDING_MESSAGE; - int firstLine = document.getLineNumber(startLineOffset); + int firstLine = document.getLineNumber(myStartLineOffset); for (int line = firstLine; line < document.getLineCount(); line++) { String lineText = document.getText(DocumentUtil.getLineTextRange(document, line)); if (lineText.startsWith("Python")) { @@ -75,14 +84,11 @@ public class PyConsoleStartFolding extends DocumentAdapter implements ConsoleCom myStartFoldRegion = foldRegion; } }); - if (isFirstCommandWasExecuted) { - document.removeDocumentListener(this); - } } @Override public void commandExecuted(boolean more) { - isFirstCommandWasExecuted = true; + myNumberOfCommandExecuted++; } @Override diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index cf2734e57a2c..86e229d84574 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -129,6 +129,7 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable PyConsoleStartFolding folding = createConsoleFolding(); // in debug console we should add folding from the place where the folding was turned on folding.setStartLineOffset(getEditor().getDocument().getTextLength()); + folding.setNumberOfCommandToStop(2); } else { myInitialized.doWhenDone(this::createConsoleFolding);