diff --git a/src/main/java/com/github/exadmin/cyberferret/async/RunnableLogger.java b/src/main/java/com/github/exadmin/cyberferret/async/RunnableLogger.java index 6e14e35..0af3133 100644 --- a/src/main/java/com/github/exadmin/cyberferret/async/RunnableLogger.java +++ b/src/main/java/com/github/exadmin/cyberferret/async/RunnableLogger.java @@ -61,15 +61,15 @@ public void run() { Platform.runLater(() -> { textArea.appendText(text); - if (textArea.getText().length() > MAX_LOG_SIZE_IN_TEXT_AREA_CHARS) { + if (textArea.getLength() > MAX_LOG_SIZE_IN_TEXT_AREA_CHARS * 2) { String currentText = textArea.getText(); - currentText = currentText.substring(CUT_PORTION); - int newLineIndex = currentText.indexOf("\n"); - currentText = currentText.substring(newLineIndex + 1); - currentText = "...\n" + currentText; - textArea.setText(currentText); - textArea.selectPositionCaret(currentText.length()); - textArea.deselect(); + int newlinePos = currentText.lastIndexOf('\n', currentText.length() - MAX_LOG_SIZE_IN_TEXT_AREA_CHARS); + if (newlinePos > 0) { + currentText = currentText.substring(newlinePos + 1); + textArea.setText(currentText); + textArea.selectPositionCaret(currentText.length()); + textArea.deselect(); + } } });