Skip to content

Commit

Permalink
#2894 moved to the platform changes handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hurricup committed Sep 15, 2024
1 parent e9e5263 commit adbfd88
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ public class PerlHeredocElementManipulator extends AbstractElementManipulator<Pe
@Override
public PerlHeredocElementImpl handleContentChange(@NotNull PerlHeredocElementImpl element, @NotNull TextRange range, String newContent)
throws IncorrectOperationException {
if (element.getTextLength() == range.getEndOffset() && !StringUtil.endsWith(newContent, "\n")) {
var contentRemoval = newContent.isEmpty();
if (element.getTextLength() == range.getEndOffset() && !contentRemoval && !StringUtil.endsWith(newContent, "\n")) {
newContent += "\n";
}

var elementText = element.getText();
String indent = "";
if (range.getStartOffset() > 0) {
var lineStart = StringUtil.skipWhitespaceBackward(elementText, range.getStartOffset() - 1);
if (lineStart < range.getStartOffset()) {
indent = elementText.substring(lineStart, range.getStartOffset());
if (!contentRemoval) {
var indent = elementText.substring(lineStart, range.getStartOffset());
newContent = prependLines(newContent, indent);
}
range = TextRange.create(lineStart, range.getEndOffset());

newContent = prependLines(newContent, indent);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<injectionConfig config="perlInjections.xml"/>
</extensions>
<extensions defaultExtensionNs="com.intellij">
<editor.injectedFileChangesHandlerProvider language="Perl5"
implementationClass="com.perl5.lang.perl.intellilang.PerlInjectedFileChangesHandlerFactory"/>
<multiHostInjector implementation="com.perl5.lang.perl.intellilang.PerlDataLanguageInjector"/>
<multiHostInjector implementation="com.perl5.lang.perl.intellilang.PerlStringLanguageInjector"/>
<multiHostInjector implementation="com.perl5.lang.perl.intellilang.PerlHeredocLanguageInjector"
Expand Down
34 changes: 34 additions & 0 deletions plugin/src/test/java/intellilang/PerlQuickEditTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,40 @@ class PerlQuickEditTest : PerlLightTestCase() {
)
}

@Test
fun testReplaceHeredoc() {
val (originalEditor, fragmentFile) = initFileWithTestSample()

myFixture.editor.selectionModel.setSelection(0, myFixture.editor.document.text.length)
myFixture.type("hello there")
assertFalse(myFixture.editor.isDisposed)
assertEquals(
"""
hello there
""".trimIndent(), myFixture.editor.document.text.trim().replace(Regex("[ \t]+\n"), "\n")
)

assertEquals(
"""
use v5.36;
sub foo{
say <<~HTML;
hello there
<div>
<html>
</html>
</div>
HTML
}""".trimIndent(), originalEditor.document.text
)
}


private fun initFileWithTestSample(): Pair<Editor, PsiFile> {
initWithTextSmart(
"""
Expand Down

0 comments on commit adbfd88

Please sign in to comment.