Skip to content

Commit 3076522

Browse files
authored
Merge pull request #191 from SeeSharpSoft/master
Release 2.9.3
2 parents 78bcc79 + f3458a2 commit 3076522

File tree

10 files changed

+72
-8
lines changed

10 files changed

+72
-8
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.9.3
2+
Mar 08, 2020
3+
4+
NEW: option to keep trailing spaces for CSV/TSV/PSV files
5+
FIX: consider escape char inside quotes as escaped text
6+
17
2.9.2
28
Feb 24, 2020
39

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ _Default Escape Character_ defines which escape character is used as standard fo
144144

145145
###### Highlight caret row
146146

147-
The highlighting of the current caret row might interfere with custom background color settings and can be enabled/disabled for CSV/TSV files here.
147+
The highlighting of the current caret row might interfere with custom background color settings and can be enabled/disabled for CSV/TSV/PSV files here.
148148

149149
###### Enable column highlighting
150150

@@ -162,7 +162,13 @@ Enable/disable the info balloon that appears at the caret position in the text e
162162

163163
###### Use soft wraps
164164

165-
Set whether soft wrapping should be activated for CSV/TSV. It still can be changed file specific with right-click on the editors left outer margin.
165+
Set whether soft wrapping should be activated for CSV/TSV/PSV. It still can be changed file specific with right-click on the editors left outer margin.
166+
167+
###### Keep trailing whitespaces
168+
169+
If enabled, it overrides the default editor settings for trailing whitespace handling to always keep them when editing CSV/TSV/PSV.
170+
171+
**Note:** This setting has no effect on the table editor. Unquoted values will always be trimmed when opening the table editor. When edited in the table editor, values ending or starting with whitespace will be quoted.
166172

167173
#### Table Editor
168174

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jacocoTestReport {
2424
}
2525

2626
group 'net.seesharpsoft.intellij.plugins'
27-
version '2.9.2'
27+
version '2.9.3'
2828

2929
apply plugin: 'java'
3030
sourceCompatibility = javaVersion

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvLexer.flex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ WHITE_SPACE=[ \f]+
9393
default:
9494
throw new RuntimeException("unhandled state: " + yystate());
9595
}
96+
return CsvTypes.ESCAPED_TEXT;
9697
}
9798
return CsvTypes.TEXT;
9899
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static final class OptionSet {
5656
public boolean FILE_END_LINE_BREAK;
5757
public CsvEscapeCharacter DEFAULT_ESCAPE_CHARACTER = ESCAPE_CHARACTER_DEFAULT;
5858
public CsvValueSeparator DEFAULT_VALUE_SEPARATOR = VALUE_SEPARATOR_DEFAULT;
59+
public boolean KEEP_TRAILING_SPACES = false;
5960

6061
public OptionSet() {
6162
EditorSettingsExternalizable editorSettingsExternalizable = EditorSettingsExternalizable.getInstance();
@@ -260,4 +261,12 @@ public void setDefaultValueSeparator(CsvValueSeparator defaultValueSeparator) {
260261
public CsvValueSeparator getDefaultValueSeparator() {
261262
return getState().DEFAULT_VALUE_SEPARATOR;
262263
}
264+
265+
public void setKeepTrailingSpaces(boolean keepTrailingSpaces) {
266+
getState().KEEP_TRAILING_SPACES = keepTrailingSpaces;
267+
}
268+
269+
public boolean getKeepTrailingSpaces() {
270+
return getState().KEEP_TRAILING_SPACES;
271+
}
263272
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.form

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</component>
5454
</children>
5555
</grid>
56-
<grid id="6ba47" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
56+
<grid id="6ba47" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
5757
<margin top="10" left="10" bottom="10" right="10"/>
5858
<constraints>
5959
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -82,6 +82,14 @@
8282
<text value="Show info balloon"/>
8383
</properties>
8484
</component>
85+
<component id="8ed01" class="javax.swing.JCheckBox" binding="cbKeepTrailingWhitespaces">
86+
<constraints>
87+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
88+
</constraints>
89+
<properties>
90+
<text value="Keep trailing whitespaces (if unchecked, general editor setting apply)"/>
91+
</properties>
92+
</component>
8593
</children>
8694
</grid>
8795
</children>

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettingsProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class CsvEditorSettingsProvider implements SearchableConfigurable {
4141
private JCheckBox cbAdjustColumnWidthOnOpen;
4242
private JComboBox comboEscapeCharacter;
4343
private JComboBox comboValueSeparator;
44+
private JCheckBox cbKeepTrailingWhitespaces;
4445

4546
@NotNull
4647
@Override
@@ -90,7 +91,8 @@ public boolean isModified() {
9091
!tfDefaultColumnWidth.getValue().equals(csvEditorSettings.getTableDefaultColumnWidth()) ||
9192
isModified(cbAdjustColumnWidthOnOpen, csvEditorSettings.isTableAutoColumnWidthOnOpen()) ||
9293
!Objects.equals(comboEscapeCharacter.getSelectedItem(), csvEditorSettings.getDefaultEscapeCharacter()) ||
93-
!Objects.equals(comboValueSeparator.getSelectedItem(), csvEditorSettings.getDefaultValueSeparator());
94+
!Objects.equals(comboValueSeparator.getSelectedItem(), csvEditorSettings.getDefaultValueSeparator()) ||
95+
isModified(cbKeepTrailingWhitespaces, csvEditorSettings.getKeepTrailingSpaces());
9496
}
9597

9698
@Override
@@ -114,6 +116,7 @@ public void reset() {
114116
cbAdjustColumnWidthOnOpen.setSelected(csvEditorSettings.isTableAutoColumnWidthOnOpen());
115117
comboEscapeCharacter.setSelectedItem(csvEditorSettings.getDefaultEscapeCharacter());
116118
comboValueSeparator.setSelectedItem(csvEditorSettings.getDefaultValueSeparator());
119+
cbKeepTrailingWhitespaces.setSelected(csvEditorSettings.getKeepTrailingSpaces());
117120
}
118121

119122
@Override
@@ -137,6 +140,7 @@ public void apply() throws ConfigurationException {
137140
csvEditorSettings.setTableAutoColumnWidthOnOpen(cbAdjustColumnWidthOnOpen.isSelected());
138141
csvEditorSettings.setDefaultEscapeCharacter((CsvEscapeCharacter)comboEscapeCharacter.getSelectedItem());
139142
csvEditorSettings.setDefaultValueSeparator((CsvValueSeparator)comboValueSeparator.getSelectedItem());
143+
csvEditorSettings.setKeepTrailingSpaces(cbKeepTrailingWhitespaces.isSelected());
140144
}
141145

142146
protected void createUIComponents() {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.seesharpsoft.intellij.plugins.csv.settings;
2+
3+
import com.intellij.openapi.editor.Document;
4+
import com.intellij.openapi.editor.StripTrailingSpacesFilter;
5+
import com.intellij.openapi.editor.StripTrailingSpacesFilterFactory;
6+
import com.intellij.openapi.fileEditor.FileDocumentManager;
7+
import com.intellij.openapi.fileTypes.LanguageFileType;
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.openapi.vfs.VirtualFile;
10+
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
public class CsvStripTrailingSpacesFilterFactory extends StripTrailingSpacesFilterFactory {
15+
@NotNull
16+
@Override
17+
public StripTrailingSpacesFilter createFilter(@Nullable Project project, @NotNull Document document) {
18+
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
19+
if (project != null &&
20+
virtualFile != null &&
21+
virtualFile.getFileType() instanceof LanguageFileType &&
22+
((LanguageFileType) virtualFile.getFileType()).getLanguage().isKindOf(CsvLanguage.INSTANCE) &&
23+
CsvEditorSettings.getInstance().getKeepTrailingSpaces()) {
24+
return StripTrailingSpacesFilter.NOT_ALLOWED;
25+
}
26+
return StripTrailingSpacesFilter.ALL_LINES;
27+
}
28+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
<change-notes><![CDATA[
5050
<pre style="font-family: sans-serif">
51-
FIX: Backslash in text is considered a special character #184
52-
FIX: NullPointerException thrown when trying to view CSV as table #185
51+
NEW: option to keep trailing spaces for CSV/TSV/PSV files
52+
FIX: consider escape char inside quotes as escaped text
5353
</pre>
5454
]]>
5555
</change-notes>
@@ -151,6 +151,8 @@ FIX: NullPointerException thrown when trying to view CSV as table #185
151151
<category>CSV</category>
152152
<descriptionDirectoryName>UnquoteAll</descriptionDirectoryName>
153153
</intentionAction>
154+
155+
<stripTrailingSpacesFilterFactory implementation="net.seesharpsoft.intellij.plugins.csv.settings.CsvStripTrailingSpacesFilterFactory" />
154156
</extensions>
155157

156158
<actions>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Header \\1\\, "Header, 2"
1+
"Header \\1\\", "Header, 2"
22
"Value \"1\"", Value 2
33
"back\\\"\"\\slash\\"

0 commit comments

Comments
 (0)