Use after line end inlays to avoid moving inlay on the next line pressing enter

^KT-29534 Fixed
This commit is contained in:
Natalia Selezneva
2019-05-30 15:22:04 +03:00
parent 5bff3ac927
commit ab0877390b
4 changed files with 41 additions and 10 deletions
@@ -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) }
}
}
@@ -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 }
@@ -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 }
@@ -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<InlayScratchFileRenderer> {
val inlineElementsInRange = myFixture.editor.inlayModel.getInlineElementsInRange(start, end)
return inlineElementsInRange
.map { it.renderer }
.filterIsInstance<InlayScratchFileRenderer>()
val inlineElementsInRange = myFixture.editor.inlayModel.getInlays(start, end)
return inlineElementsInRange.map { it.renderer as InlayScratchFileRenderer }
}
private fun configureOptions(