Skip to content

Commit de2e84c

Browse files
committed
prevent custom CSV editors for diff views
1 parent 7ff7930 commit de2e84c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor;
22

3+
import com.intellij.diff.editor.DiffVirtualFile;
34
import com.intellij.openapi.editor.EditorSettings;
45
import com.intellij.openapi.fileEditor.*;
56
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
@@ -16,6 +17,10 @@ public class CsvFileEditorProvider implements AsyncFileEditorProvider, DumbAware
1617

1718
public static final String EDITOR_TYPE_ID = "csv-text-editor";
1819

20+
public static boolean acceptCsvFile(@NotNull Project project, @NotNull VirtualFile file) {
21+
return CsvHelper.isCsvFile(project, file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file) && !(file instanceof DiffVirtualFile);
22+
}
23+
1924
@Override
2025
public String getEditorTypeId() {
2126
return EDITOR_TYPE_ID;
@@ -36,7 +41,7 @@ public FileEditorPolicy getPolicy() {
3641

3742
@Override
3843
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
39-
return CsvHelper.isCsvFile(project, file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file);
44+
return CsvFileEditorProvider.acceptCsvFile(project, file);
4045
}
4146

4247
protected void applySettings(EditorSettings editorSettings, CsvEditorSettings csvEditorSettings) {

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void setEditable(boolean editable) {
102102
}
103103

104104
public boolean isEditable() {
105-
return this.tableIsEditable && !this.hasErrors() && !hasComments();
105+
return this.tableIsEditable && !this.hasErrors() && !hasComments() && file.isWritable();
106106
}
107107

108108
public CsvColumnInfoMap<PsiElement> getColumnInfoMap() {

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import com.intellij.openapi.project.DumbAware;
88
import com.intellij.openapi.project.Project;
99
import com.intellij.openapi.vfs.VirtualFile;
10-
import com.intellij.psi.SingleRootFileViewProvider;
11-
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
10+
import net.seesharpsoft.intellij.plugins.csv.editor.CsvFileEditorProvider;
1211
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
1312
import net.seesharpsoft.intellij.plugins.csv.editor.table.swing.CsvTableEditorSwing;
1413
import org.jdom.Element;
@@ -39,8 +38,7 @@ public FileEditorPolicy getPolicy() {
3938
@Override
4039
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
4140
return CsvEditorSettings.getInstance().getEditorPrio() != CsvEditorSettings.EditorPrio.TEXT_ONLY &&
42-
CsvHelper.isCsvFile(project, file) &&
43-
!SingleRootFileViewProvider.isTooLargeForIntelligence(file);
41+
CsvFileEditorProvider.acceptCsvFile(project, file);
4442
}
4543

4644
@NotNull

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor;
22

3+
import com.intellij.diff.editor.DiffVirtualFile;
4+
import com.intellij.diff.impl.DiffRequestProcessor;
35
import com.intellij.openapi.editor.EditorSettings;
46
import com.intellij.openapi.fileEditor.*;
57
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
68
import com.intellij.openapi.fileEditor.impl.text.TextEditorState;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.vcs.changes.PreviewDiffVirtualFile;
11+
import com.intellij.testFramework.LightVirtualFile;
712
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
813
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
914
import org.jdom.Element;
15+
import org.jetbrains.annotations.NotNull;
1016

1117
public class CsvFileEditorTest extends BasePlatformTestCase {
1218

@@ -93,4 +99,19 @@ public void testCsvEditorStateReadsAndWritesStates() {
9399
disposeTextEditor(textEditor);
94100
}
95101

102+
private static class DiffVirtualFileDummy extends DiffVirtualFile {
103+
public DiffVirtualFileDummy(@NotNull String name) {
104+
super(name);
105+
}
106+
107+
@Override
108+
public DiffRequestProcessor createProcessor(@NotNull Project project) {
109+
return null;
110+
}
111+
}
112+
113+
public void testAcceptCsvFile() {
114+
assertTrue(CsvFileEditorProvider.acceptCsvFile(myFixture.getProject(), new LightVirtualFile(myFixture.getFile().getName())));
115+
assertFalse(CsvFileEditorProvider.acceptCsvFile(myFixture.getProject(), new DiffVirtualFileDummy(myFixture.getFile().getName())));
116+
}
96117
}

0 commit comments

Comments
 (0)