From adbfd88d0cf4d69425681136cc9920797231b723 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sun, 15 Sep 2024 10:57:53 +0400 Subject: [PATCH] #2894 moved to the platform changes handler --- .../PerlHeredocElementManipulator.java | 11 +- ...PerlInjectedFileChangesHandlerFactory.java | 103 ------------------ .../resources/perl5.plugin.intelliLang.xml | 2 - .../java/intellilang/PerlQuickEditTest.kt | 34 ++++++ 4 files changed, 40 insertions(+), 110 deletions(-) delete mode 100644 plugin/intelliLang/src/main/java/com/perl5/lang/perl/intellilang/PerlInjectedFileChangesHandlerFactory.java diff --git a/plugin/core/src/main/java/com/perl5/lang/perl/idea/manipulators/PerlHeredocElementManipulator.java b/plugin/core/src/main/java/com/perl5/lang/perl/idea/manipulators/PerlHeredocElementManipulator.java index a2dd58d0e7..419d14bfce 100644 --- a/plugin/core/src/main/java/com/perl5/lang/perl/idea/manipulators/PerlHeredocElementManipulator.java +++ b/plugin/core/src/main/java/com/perl5/lang/perl/idea/manipulators/PerlHeredocElementManipulator.java @@ -30,19 +30,20 @@ public class PerlHeredocElementManipulator extends AbstractElementManipulator 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); } } diff --git a/plugin/intelliLang/src/main/java/com/perl5/lang/perl/intellilang/PerlInjectedFileChangesHandlerFactory.java b/plugin/intelliLang/src/main/java/com/perl5/lang/perl/intellilang/PerlInjectedFileChangesHandlerFactory.java deleted file mode 100644 index 43b6451f2f..0000000000 --- a/plugin/intelliLang/src/main/java/com/perl5/lang/perl/intellilang/PerlInjectedFileChangesHandlerFactory.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.perl5.lang.perl.intellilang; - -import com.intellij.injected.editor.InjectedFileChangesHandler; -import com.intellij.injected.editor.InjectedFileChangesHandlerProvider; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.event.DocumentEvent; -import com.intellij.openapi.util.ProperTextRange; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.ElementManipulators; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLanguageInjectionHost; -import com.intellij.psi.impl.source.tree.injected.changesHandler.CommonInjectedFileChangesHandler; -import com.intellij.psi.impl.source.tree.injected.changesHandler.MarkersMapping; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -@ApiStatus.ScheduledForRemoval(inVersion = "2020.3") -@Deprecated -public class PerlInjectedFileChangesHandlerFactory implements InjectedFileChangesHandlerProvider { - @Override - public InjectedFileChangesHandler createFileChangesHandler(List shreds, - Editor hostEditor, - Document newDocument, - PsiFile injectedFile) { - return new PerlInjectedChangesHandler(shreds, hostEditor, newDocument, injectedFile); - } - - private static class PerlInjectedChangesHandler extends CommonInjectedFileChangesHandler { - public PerlInjectedChangesHandler(@NotNull List shreds, - @NotNull Editor hostEditor, - @NotNull Document fragmentDocument, - @NotNull PsiFile injectedFile) { - super(shreds, hostEditor, fragmentDocument, injectedFile); - } - - @Override - public void commitToOriginal(@NotNull DocumentEvent e) { - var text = myFragmentDocument.getText(); - var map = ContainerUtil.groupBy(getMarkers(), MarkersMapping::getHost); - - var documentManager = PsiDocumentManager.getInstance(myProject); - documentManager.commitDocument(myHostDocument); - - for (PsiLanguageInjectionHost host : map.keySet()) { - if (host == null) { - continue; - } - var hostRange = host.getTextRange(); - var hostOffset = hostRange.getStartOffset(); - var originalText = host.getText(); - var currentHost = host; - var mappings = new ArrayList<>(map.get(host)); - if (mappings.isEmpty()) { - continue; - } - Collections.reverse(mappings); - - for (var mapping : mappings) { - var hostMarker = mapping.getHostMarker(); - var fragmentMarker = mapping.getFragmentMarker(); - var localInsideHost = new ProperTextRange(hostMarker.getStartOffset() - hostOffset, hostMarker.getEndOffset() - hostOffset); - var localInsideFile = new ProperTextRange(fragmentMarker.getStartOffset(), fragmentMarker.getEndOffset()); - - if (localInsideFile.getEndOffset() <= text.length() && !localInsideFile.isEmpty()) { - var decodedText = localInsideFile.substring(text); - if (!StringUtil.equals(decodedText, localInsideHost.subSequence(currentHost.getText()))) { - currentHost = ElementManipulators.handleContentChange(currentHost, localInsideHost, decodedText); - if (currentHost == null) { - failAndReport("Updating host returned null. Original host" + host + - "; original text: " + originalText + - "; updated range in host: " + localInsideHost + - "; decoded text to replace: " + decodedText, e, null); - } - } - } - } - } - } - } -} diff --git a/plugin/intelliLang/src/main/resources/perl5.plugin.intelliLang.xml b/plugin/intelliLang/src/main/resources/perl5.plugin.intelliLang.xml index ceae50433e..e4cf40144f 100644 --- a/plugin/intelliLang/src/main/resources/perl5.plugin.intelliLang.xml +++ b/plugin/intelliLang/src/main/resources/perl5.plugin.intelliLang.xml @@ -28,8 +28,6 @@ - + + + + HTML + }""".trimIndent(), originalEditor.document.text + ) + } + + private fun initFileWithTestSample(): Pair { initWithTextSmart( """