diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcInlineValueProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/PcInlineValueProvider.scala index eafac513c7e1..816a016fa027 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcInlineValueProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcInlineValueProvider.scala @@ -133,11 +133,8 @@ final class PcInlineValueProvider( rhsLines match case h :: Nil => rhs case h :: t => - val noPrefixH = h.stripPrefix(refIndent) - if noPrefixH.startsWith("{") then - noPrefixH ++ t.map(refIndent ++ _.stripPrefix(defIndent)).mkString("\n","\n", "") - else - ((" " ++ h) :: t).map(refIndent ++ _.stripPrefix(defIndent)).mkString("\n", "\n", "") + val header = if h.startsWith("{") then h else "\n" ++ refIndent ++ " " ++ h + header ++ t.map(refIndent ++ _.stripPrefix(defIndent)).mkString("\n", "\n", "") case Nil => rhs private def definitionRequiresBrackets(tree: Tree)(using Context): Boolean = @@ -232,7 +229,7 @@ final class PcInlineValueProvider( var idx = source.startOfLine(offset) val pad = new StringBuilder while (idx != offset && idx < source.content().length && source.content()(idx).isWhitespace) { - pad.append(if (idx < source.content().length && source.content()(idx) == '\t') '\t' else ' ') + pad.append(source.content()(idx)) idx += 1 } pad.result() diff --git a/presentation-compiler/test/dotty/tools/pc/tests/edit/InlineValueSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/edit/InlineValueSuite.scala index 541340bd3f38..e53b015d0d86 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/edit/InlineValueSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/edit/InlineValueSuite.scala @@ -430,6 +430,25 @@ class InlineValueSuite extends BaseCodeActionSuite with CommonMtagsEnrichments: ) @Test def `i7137a` = + checkEdit( + """|def foo = { + | val newValue = + | val x = true + | x + | def bar = + | val xx =new<>alue + |} + |""".stripMargin, + """|def foo = { + | def bar = + | val xx = + | val x = true + | x + |} + |""".stripMargin + ) + + @Test def `i7137b` = checkEdit( """|object O { | def foo = {