diff --git a/src/com/funivan/phpstorm/refactoring/EditUsages/CreateCustomPatchFromUsages.java b/src/com/funivan/phpstorm/refactoring/EditUsages/CreateCustomPatchFromUsages.java index 454e9e6..0b48e19 100644 --- a/src/com/funivan/phpstorm/refactoring/EditUsages/CreateCustomPatchFromUsages.java +++ b/src/com/funivan/phpstorm/refactoring/EditUsages/CreateCustomPatchFromUsages.java @@ -6,8 +6,11 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.usages.Usage; @@ -15,6 +18,8 @@ import com.intellij.usages.UsageView; import com.intellij.usages.impl.UsageViewImpl; +import java.util.HashMap; +import java.util.Map; import java.util.Set; /** @@ -43,6 +48,9 @@ public void actionPerformed(AnActionEvent e) { StringBuilder buf = new StringBuilder(); + + Map processedLines = new HashMap<>(); + for (Usage usage : usages) { if (!(usage instanceof UsageInfo2UsageAdapter)) { @@ -58,12 +66,29 @@ public void actionPerformed(AnActionEvent e) { VirtualFile file = usageInfo.getFile(); + int line = usageInfo.getLine(); String path = VfsUtil.getRelativePath(file, baseDir, '/'); + String key = path + ":" + line; + + if (processedLines.get(key) != null) { + continue; + } + + Document fileDocument = FileDocumentManager.getInstance().getDocument(file); + + + int startOffset = fileDocument.getLineStartOffset(line); + int endOffset = fileDocument.getLineEndOffset(line); + + String text = fileDocument.getText(new TextRange(startOffset, endOffset)); + buf.append("\n"); - buf.append("//file:" + path + ':' + (usageInfo.getLine() + 1) + "\n"); - buf.append(usageInfo.getPlainText() + "\n"); + buf.append("//file:" + path + ':' + (line + 1) + "\n"); + buf.append(text + "\n"); buf.append("\n"); + + processedLines.put(key, true); }