From ef4bac1b46a71d6662fe535b15aa0f14ec74cbc2 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 16 Aug 2019 19:02:18 +0700 Subject: [PATCH] REPL: fix `IllegalArgumentException` Reproduce: select `Pause Output` #EA-209571 Fixed #EA-210364 Fixed #KT-33329 Fixed --- .../org/jetbrains/kotlin/console/HistoryUpdater.kt | 3 ++- .../jetbrains/kotlin/console/ReplOutputProcessor.kt | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/HistoryUpdater.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/HistoryUpdater.kt index 76a0837a490..ea1d085a298 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/HistoryUpdater.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/HistoryUpdater.kt @@ -31,9 +31,10 @@ class HistoryUpdater(private val runner: KotlinConsoleRunner) { val historyEditor = consoleView.historyViewer addLineBreakIfNeeded(historyEditor) val startOffset = historyEditor.document.textLength - val endOffset = startOffset + trimmedCommandText.length addCommandTextToHistoryEditor(trimmedCommandText) + val endOffset = historyEditor.document.textLength + addFoldingRegion(historyEditor, startOffset, endOffset, trimmedCommandText) historyEditor.markupModel.addRangeHighlighter( diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputProcessor.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputProcessor.kt index 22622c050de..0fa4a7dbb9a 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputProcessor.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/ReplOutputProcessor.kt @@ -46,19 +46,13 @@ class ReplOutputProcessor( private val historyDocument = historyEditor.document private val historyMarkup = historyEditor.markupModel - private fun textOffsets(text: String): Pair { - consoleView.flushDeferredText() // flush before getting offsets to calculate them properly - val oldLen = historyDocument.textLength - val newLen = oldLen + text.length - - return Pair(oldLen, newLen) - } - private fun printOutput(output: String, contentType: ConsoleViewContentType, iconWithTooltip: IconWithTooltip? = null) { - val (startOffset, endOffset) = textOffsets(output) + consoleView.flushDeferredText() // flush before getting offsets to calculate them properly + val startOffset = historyDocument.textLength consoleView.print(output, contentType) consoleView.flushDeferredText() + val endOffset = historyDocument.textLength if (iconWithTooltip == null) return