diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt index 4089eeb3c06..fbba13b8c22 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchOutputHandler.kt @@ -74,16 +74,15 @@ object InlayScratchOutputHandler : ScratchOutputHandler { if (shortText != text) { printToToolWindow(file, expression, output) } - editor.inlayModel.addInlineElement( + editor.inlayModel.addInlay( lineEndOffset, - true, InlayScratchFileRenderer(" ".repeat(spaceCount) + shortText, output.type) ) } val existing = editor.inlayModel - .getInlineElementsInRange(lineEndOffset, lineEndOffset) - .singleOrNull { it.renderer is InlayScratchFileRenderer } + .getInlays(lineEndOffset, lineEndOffset) + .singleOrNull() if (existing != null) { existing.dispose() addInlay(((existing.renderer as InlayScratchFileRenderer).text + "; " + output.text).drop(spaceCount)) @@ -110,8 +109,7 @@ object InlayScratchOutputHandler : ScratchOutputHandler { private fun clearInlays(editor: TextEditor) { UIUtil.invokeLaterIfNeeded { editor - .editor.inlayModel.getInlineElementsInRange(0, editor.editor.document.textLength) - .filter { it.renderer is InlayScratchFileRenderer } + .editor.inlayModel.getInlays(0, editor.editor.document.textLength) .forEach { Disposer.dispose(it) } } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt new file mode 100644 index 00000000000..16db70298ef --- /dev/null +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("UnstableApiUsage") + +package org.jetbrains.kotlin.idea.scratch.output + +import com.intellij.openapi.editor.InlayModel + +fun InlayModel.addInlay(offset: Int, renderer: InlayScratchFileRenderer) { + addAfterLineEndElement(offset, false, renderer) +} + +fun InlayModel.getInlays(start: Int, end: Int) = + getAfterLineEndElementsInRange(start, end).filter { it.renderer is InlayScratchFileRenderer } \ No newline at end of file diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt.as33 b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt.as33 new file mode 100644 index 00000000000..9ab71128e1a --- /dev/null +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/inlayHelper.kt.as33 @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("UnstableApiUsage") + +package org.jetbrains.kotlin.idea.scratch.output + +import com.intellij.openapi.editor.InlayModel + +fun InlayModel.addInlay(offset: Int, renderer: InlayScratchFileRenderer) { + addInlineElement(offset, true, renderer) +} + +fun InlayModel.getInlays(start: Int, end: Int) = + getInlineElementsInRange(start, end).filter { it.renderer is InlayScratchFileRenderer } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt index 74465570e58..4f032944961 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.scratch.actions.ClearScratchAction import org.jetbrains.kotlin.idea.scratch.actions.RunScratchAction import org.jetbrains.kotlin.idea.scratch.actions.ScratchCompilationSupport import org.jetbrains.kotlin.idea.scratch.output.InlayScratchFileRenderer +import org.jetbrains.kotlin.idea.scratch.output.getInlays import org.jetbrains.kotlin.idea.scratch.ui.ScratchTopPanel import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor @@ -135,10 +136,8 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { } protected fun getInlays(start: Int = 0, end: Int = myFixture.file.textLength): List { - val inlineElementsInRange = myFixture.editor.inlayModel.getInlineElementsInRange(start, end) - return inlineElementsInRange - .map { it.renderer } - .filterIsInstance() + val inlineElementsInRange = myFixture.editor.inlayModel.getInlays(start, end) + return inlineElementsInRange.map { it.renderer as InlayScratchFileRenderer } } private fun configureOptions(