Repl, minor: extract function

This commit is contained in:
Pavel V. Talanov
2015-10-22 17:48:28 +03:00
parent b07fb88a22
commit b5dfbcdde8
@@ -41,30 +41,31 @@ public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner )
fun printNewCommandInHistory(trimmedCommandText: String) { fun printNewCommandInHistory(trimmedCommandText: String) {
val historyEditor = consoleView.historyViewer val historyEditor = consoleView.historyViewer
addLineBreakIfNeeded(historyEditor) addLineBreakIfNeeded(historyEditor)
val consoleEditor = consoleView.consoleEditor
val consoleDocument = consoleEditor.document
consoleDocument.setText(trimmedCommandText)
val startOffset = historyEditor.document.textLength val startOffset = historyEditor.document.textLength
val endOffset = startOffset + trimmedCommandText.length() val endOffset = startOffset + trimmedCommandText.length()
LanguageConsoleImpl.printWithHighlighting(consoleView, consoleEditor, TextRange(0, consoleDocument.textLength)) addCommandTextToHistoryEditor(trimmedCommandText)
consoleView.flushDeferredText()
EditorUtil.scrollToTheEnd(historyEditor) EditorUtil.scrollToTheEnd(historyEditor)
consoleDocument.setText("")
addFoldingRegion(historyEditor, startOffset, endOffset, trimmedCommandText) addFoldingRegion(historyEditor, startOffset, endOffset, trimmedCommandText)
historyEditor.markupModel.addRangeHighlighter( historyEditor.markupModel.addRangeHighlighter(
startOffset, endOffset, HighlighterLayer.LAST, null, HighlighterTargetArea.EXACT_RANGE startOffset, endOffset, HighlighterLayer.LAST, null, HighlighterTargetArea.EXACT_RANGE
) apply { ).apply {
val historyMarker = if (isReadLineMode) ReplIcons.READLINE_MARKER else ReplIcons.COMMAND_MARKER val historyMarker = if (isReadLineMode) ReplIcons.READLINE_MARKER else ReplIcons.COMMAND_MARKER
gutterIconRenderer = KotlinConsoleIndicatorRenderer(historyMarker) gutterIconRenderer = KotlinConsoleIndicatorRenderer(historyMarker)
} }
} }
private fun addCommandTextToHistoryEditor(trimmedCommandText: String) {
val consoleEditor = consoleView.consoleEditor
val consoleDocument = consoleEditor.document
consoleDocument.setText(trimmedCommandText)
LanguageConsoleImpl.printWithHighlighting(consoleView, consoleEditor, TextRange(0, consoleDocument.textLength))
consoleView.flushDeferredText()
consoleDocument.setText("")
}
private fun addLineBreakIfNeeded(historyEditor: EditorEx) { private fun addLineBreakIfNeeded(historyEditor: EditorEx) {
if (isReadLineMode) return if (isReadLineMode) return