diff --git a/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala b/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala index 20d18535328..44d75db4eeb 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/formatting/MultilineString.scala @@ -60,9 +60,11 @@ case class MultilineString(userConfig: () => UserConfiguration) val index = if (lineToCheck.contains("\"\"\"|")) { lineToCheck.indexOf('"') + 3 + } else if (lineToCheck.contains("|")) { + lineToCheck.indexOf('|') } else if (lineToCheck.contains("\"\"\"")) { lineToCheck.indexOf('"') + 2 - } else lineToCheck.indexOf('|') + } else 0 space * index } diff --git a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala index d2e72d470c0..f3cf74ec180 100644 --- a/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala +++ b/tests/unit/src/test/scala/tests/rangeFormatting/MultilineStringRangeFormattingWhenPastingSuite.scala @@ -339,6 +339,19 @@ class MultilineStringRangeFormattingWhenPastingSuite |}""".stripMargin, ) + check( + "i6798", + s"""|val x = + | s'''|Hello + | |Good@@'''.stripMargin + |}""".stripMargin, + "bye", + s"""|val x = + | s'''|Hello + | |Goodbye'''.stripMargin + |}""".stripMargin, + ) + def check( name: TestOptions, testCase: String, @@ -358,7 +371,7 @@ class MultilineStringRangeFormattingWhenPastingSuite s"""/metals.json |{"a":{}} |/a/src/main/scala/a/Main.scala - """.stripMargin + base + |""".stripMargin + base ) _ <- server.didOpen("a/src/main/scala/a/Main.scala") _ <- server.rangeFormatting(