Skip to content

Commit

Permalink
#2894 do not inject into last newline
Browse files Browse the repository at this point in the history
  • Loading branch information
hurricup committed Sep 21, 2024
1 parent e67e3ad commit e8211ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ public boolean isOneLine() {

@Override
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
var hostTextLength = myHost.getTextLength();
var endOffset = rangeInsideHost.getEndOffset();
if (endOffset == hostTextLength) {
endOffset--;
}
outChars.append(myHost.getNode().getChars().subSequence(rangeInsideHost.getStartOffset(), endOffset));
outChars.append(rangeInsideHost.subSequence(myHost.getNode().getChars()));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
private void addPlace(@NotNull PerlHeredocElementImpl heredocElement, @NotNull MultiHostRegistrar registrar) {
int indentSize = heredocElement.getRealIndentSize();
if (indentSize == 0) {
registrar.addPlace(null, null, heredocElement, ElementManipulators.getValueTextRange(heredocElement));
var elementRange = ElementManipulators.getValueTextRange(heredocElement);
registrar.addPlace(null, null, heredocElement, TextRange.create(elementRange.getStartOffset(), elementRange.getEndOffset() - 1));
return;
}

Expand All @@ -107,8 +108,13 @@ private void addPlace(@NotNull PerlHeredocElementImpl heredocElement, @NotNull M
while (sourceOffset < sourceLength) {
char currentChar = sourceText.charAt(sourceOffset);
if (currentChar == '\n') {
var suffix = sourceOffset + 1 < sourceLength ? null : "\n";
registrar.addPlace(null, suffix, heredocElement, TextRange.from(sourceOffset, 1));
String suffix = null;
int endOffset = sourceOffset + 1;
if (endOffset == sourceLength) {
suffix = "\n";
endOffset--;
}
registrar.addPlace(null, suffix, heredocElement, TextRange.create(sourceOffset, endOffset));
currentLineIndent = 0;
}
else if (Character.isWhitespace(currentChar) && currentLineIndent < indentSize) {
Expand All @@ -125,7 +131,11 @@ else if (Character.isWhitespace(currentChar) && currentLineIndent < indentSize)
}
}

var suffix = sourceEnd < sourceLength ? null : "\n";
String suffix = null;
if (sourceEnd == sourceLength) {
suffix = "\n";
sourceEnd--;
}

registrar.addPlace(null, suffix, heredocElement, TextRange.create(sourceOffset, sourceEnd));
sourceOffset = sourceEnd;
Expand Down

0 comments on commit e8211ce

Please sign in to comment.