From 29f0e1f7a6f052af867d6542a89487cd9cbacd81 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sun, 15 Sep 2024 11:56:06 +0400 Subject: [PATCH] #2894 handled empty heredoc injection (need to adjust indentation for the first element) --- .../intellilang/PerlHeredocLiteralEscaper.java | 15 ++++++++++++--- .../test/java/intellilang/PerlQuickEditTest.kt | 10 +--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/core/src/main/java/com/perl5/lang/perl/idea/intellilang/PerlHeredocLiteralEscaper.java b/plugin/core/src/main/java/com/perl5/lang/perl/idea/intellilang/PerlHeredocLiteralEscaper.java index cae76494b6..f8bb678724 100644 --- a/plugin/core/src/main/java/com/perl5/lang/perl/idea/intellilang/PerlHeredocLiteralEscaper.java +++ b/plugin/core/src/main/java/com/perl5/lang/perl/idea/intellilang/PerlHeredocLiteralEscaper.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,17 @@ public boolean isOneLine() { @Override public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) { - outChars.append(rangeInsideHost.subSequence(myHost.getNode().getChars())); - return true; + var hostTextLength = myHost.getTextLength(); + var effectiveRange = hostTextLength < rangeInsideHost.getEndOffset() ? + rangeInsideHost : + TextRange.create(rangeInsideHost.getStartOffset(), rangeInsideHost.getEndOffset() - 1); + if (!effectiveRange.isEmpty()) { + outChars.append(rangeInsideHost.subSequence(myHost.getNode().getChars())); + return true; + } + else { + return false; + } } @Override diff --git a/plugin/src/test/java/intellilang/PerlQuickEditTest.kt b/plugin/src/test/java/intellilang/PerlQuickEditTest.kt index d50c159208..54404389d1 100644 --- a/plugin/src/test/java/intellilang/PerlQuickEditTest.kt +++ b/plugin/src/test/java/intellilang/PerlQuickEditTest.kt @@ -154,15 +154,7 @@ class PerlQuickEditTest : PerlLightTestCase() { sub foo{ say <<~HTML; - - - - hello there - -
- - -
+ hello there HTML }""".trimIndent(), originalEditor.document.text )