1.13 Add Copy With Line Comment & Add Line Comment | 增加 带行末注释复制 和 添加行末注释

This commit is contained in:
林万程
2022-04-10 19:42:26 +08:00
parent 595d3730d4
commit baa50ba361
29 changed files with 385 additions and 185 deletions

View File

@@ -5,16 +5,14 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorLinePainter;
import com.intellij.openapi.editor.LineExtensionInfo;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiManager;
import com.intellij.psi.javadoc.PsiDocComment;
import io.github.linwancen.plugin.show.doc.DocTextUtils;
import io.github.linwancen.plugin.show.line.LineDocLeftToRightUtils;
import io.github.linwancen.plugin.show.line.LineDocRightToLeftUtils;
import io.github.linwancen.plugin.show.ext.LineExtUtils;
import io.github.linwancen.plugin.show.line.FileViewToDocStrUtils;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -51,13 +49,18 @@ public class LineEnd extends EditorLinePainter {
private static @Nullable String doc(@NotNull Project project,
@NotNull VirtualFile file, int lineNumber) {
FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file);
if (viewProvider == null) {
return null;
}
Document document = viewProvider.getDocument();
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null) {
return null;
}
return doc(document, lineNumber, project, file, viewProvider);
}
@Nullable
private static String doc(@NotNull Document document, int lineNumber,
@Nullable Project project,
@Nullable VirtualFile file,
@Nullable FileViewProvider viewProvider) {
// lineNumber start 0, as 1 <= 1 should return
if (document.getLineCount() <= lineNumber) {
return null;
@@ -67,13 +70,7 @@ public class LineEnd extends EditorLinePainter {
if (startOffset == endOffset) {
return null;
}
String ext = LineExtUtils.extDoc(project, file, document, startOffset, endOffset);
if (ext != null) {
return ext;
}
PsiDocComment docComment = AppSettingsState.getInstance().findElementRightToLeft
? LineDocRightToLeftUtils.rightDoc(viewProvider, startOffset, endOffset)
: LineDocLeftToRightUtils.leftDoc(viewProvider, document, startOffset, endOffset);
return DocTextUtils.text(docComment);
String text = document.getText(new TextRange(startOffset, endOffset));
return FileViewToDocStrUtils.doc(document, project, file, viewProvider, startOffset, endOffset, text);
}
}