From c9257b6f4751b4a3a08fa76c7031c45f6604e373 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sun, 15 Sep 2024 12:31:03 +0400 Subject: [PATCH] #2894 final fix --- .../idea/intellilang/PerlHeredocLiteralEscaper.java | 2 +- .../testFixtures/java/base/PerlLightTestCaseBase.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 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 f8bb678724..2da7b01b04 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 @@ -36,7 +36,7 @@ public boolean isOneLine() { @Override public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) { var hostTextLength = myHost.getTextLength(); - var effectiveRange = hostTextLength < rangeInsideHost.getEndOffset() ? + var effectiveRange = rangeInsideHost.getEndOffset() < hostTextLength ? rangeInsideHost : TextRange.create(rangeInsideHost.getStartOffset(), rangeInsideHost.getEndOffset() - 1); if (!effectiveRange.isEmpty()) { diff --git a/plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java b/plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java index 26cf511f85..76c8953373 100644 --- a/plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java +++ b/plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java @@ -1377,8 +1377,14 @@ protected T getElementAtCaretWithoutInjection(@NotNull Cl } protected @NotNull PsiElement getElementAtCaretWithoutInjection() { - PsiElement result = getFile().getViewProvider().findElementAt(getEditor().getCaretModel().getOffset()); - assertNotNull(result); + PsiElement result; + if (getFile().getText().isEmpty()) { + result = getFile(); + } + else { + result = getFile().getViewProvider().findElementAt(getEditor().getCaretModel().getOffset()); + assertNotNull(result); + } PsiFile leafFile = result.getContainingFile(); if (InjectedLanguageManager.getInstance(getProject()).isInjectedFragment(leafFile)) { result = leafFile.getContext();