Fix bug with SciNotes and Console at Scilab's restart under win 62/12762/2
Calixte DENIZET [Mon, 30 Sep 2013 16:35:58 +0000 (18:35 +0200)]
Change-Id: I9727e9987cadbe0f675eafffa81813c84ab59de4

scilab/modules/console/src/java/org/scilab/modules/console/SciConsole.java

index 57d775b..685c2cb 100644 (file)
@@ -336,13 +336,15 @@ public abstract class SciConsole extends JPanel {
                 }
             }
 
-            int numberOfLines = Math.max(1, getNumberOfLines());
+            int numberOfLines = getNumberOfLines();
             int promptWidth = ((JPanel) this.getConfiguration().getPromptView()).getPreferredSize().width;
 
             int numberOfColumns = (outputViewWidth - promptWidth) / maxCharWidth - 1;
             /* -1 because of the margin between text prompt and command line text */
 
-            GuiManagement.setScilabLines(numberOfLines, numberOfColumns);
+            if (numberOfLines > 0 && numberOfColumns > 0) {
+                GuiManagement.setScilabLines(Math.max(1, numberOfLines), numberOfColumns);
+            }
         } else {
             GuiManagement.forceScilabLines(ConsoleOptions.getConsoleDisplay().nbLines, ConsoleOptions.getConsoleDisplay().nbColumns);
         }
@@ -445,7 +447,9 @@ public abstract class SciConsole extends JPanel {
                     for (int i = 0; i < totalNumberOfLines; i++) {
                         outputTxt = outputDoc.getText(0, outputDoc.getLength());
                         lastEOL = outputTxt.lastIndexOf(StringConstants.NEW_LINE);
-                        outputDoc.remove(lastEOL, outputDoc.getLength() - lastEOL);
+                        if (lastEOL != -1) {
+                            outputDoc.remove(lastEOL, outputDoc.getLength() - lastEOL);
+                        }
                     }
                 }
             } catch (BadLocationException e) {