@@ -199,8 +199,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
199199 */
200200 private async updateDocument ( row : number , col : number , value : string ) {
201201 this . isUpdatingDocument = true ;
202- const config = vscode . workspace . getConfiguration ( 'csv' ) ;
203- const separator = config . get < string > ( 'separator' , ',' ) ;
202+ const separator = this . getSeparator ( ) ;
204203 const oldText = this . document . getText ( ) ;
205204 const lines = oldText . split ( / \r ? \n / ) ;
206205 let editSucceeded = false ;
@@ -261,8 +260,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
261260 */
262261 private async insertColumn ( index : number ) {
263262 this . isUpdatingDocument = true ;
264- const config = vscode . workspace . getConfiguration ( 'csv' ) ;
265- const separator = config . get < string > ( 'separator' , ',' ) ;
263+ const separator = this . getSeparator ( ) ;
266264 const text = this . document . getText ( ) ;
267265 const result = Papa . parse ( text , { dynamicTyping : false , delimiter : separator } ) ;
268266 const data = result . data as string [ ] [ ] ;
@@ -286,8 +284,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
286284 */
287285 private async deleteColumn ( index : number ) {
288286 this . isUpdatingDocument = true ;
289- const config = vscode . workspace . getConfiguration ( 'csv' ) ;
290- const separator = config . get < string > ( 'separator' , ',' ) ;
287+ const separator = this . getSeparator ( ) ;
291288 const text = this . document . getText ( ) ;
292289 const result = Papa . parse ( text , { dynamicTyping : false , delimiter : separator } ) ;
293290 const data = result . data as string [ ] [ ] ;
@@ -313,7 +310,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
313310 this . isUpdatingDocument = true ;
314311
315312 const config = vscode . workspace . getConfiguration ( 'csv' ) ;
316- const separator = config . get < string > ( 'separator' , ',' ) ;
313+ const separator = this . getSeparator ( ) ;
317314 const treatHeader = config . get < boolean > ( 'treatFirstRowAsHeader' , true ) ;
318315
319316 const text = this . document . getText ( ) ;
@@ -364,8 +361,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
364361 */
365362 private async insertRow ( index : number ) {
366363 this . isUpdatingDocument = true ;
367- const config = vscode . workspace . getConfiguration ( 'csv' ) ;
368- const separator = config . get < string > ( 'separator' , ',' ) ;
364+ const separator = this . getSeparator ( ) ;
369365 const text = this . document . getText ( ) ;
370366 const result = Papa . parse ( text , { dynamicTyping : false , delimiter : separator } ) ;
371367 const data = result . data as string [ ] [ ] ;
@@ -389,8 +385,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
389385 */
390386 private async deleteRow ( index : number ) {
391387 this . isUpdatingDocument = true ;
392- const config = vscode . workspace . getConfiguration ( 'csv' ) ;
393- const separator = config . get < string > ( 'separator' , ',' ) ;
388+ const separator = this . getSeparator ( ) ;
394389 const text = this . document . getText ( ) ;
395390 const result = Papa . parse ( text , { dynamicTyping : false , delimiter : separator } ) ;
396391 const data = result . data as string [ ] [ ] ;
@@ -415,7 +410,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
415410 const config = vscode . workspace . getConfiguration ( 'csv' ) ;
416411 const treatHeader = config . get < boolean > ( 'treatFirstRowAsHeader' , true ) ;
417412 const addSerialIndex = config . get < boolean > ( 'addSerialIndex' , false ) ;
418- const separator = config . get < string > ( 'separator' , ',' ) ;
413+ const separator = this . getSeparator ( ) ;
419414 const text = this . document . getText ( ) ;
420415 let result ;
421416 try {
@@ -1043,6 +1038,19 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
10431038 return widths ;
10441039 }
10451040
1041+ /**
1042+ * Determines the delimiter to use based on configuration and file extension.
1043+ * `.tsv` files default to a tab separator when the setting is untouched.
1044+ */
1045+ private getSeparator ( ) : string {
1046+ const config = vscode . workspace . getConfiguration ( 'csv' ) ;
1047+ let sep = config . get < string > ( 'separator' , ',' ) ;
1048+ if ( sep === ',' && this . document ?. uri . fsPath . toLowerCase ( ) . endsWith ( '.tsv' ) ) {
1049+ sep = '\t' ;
1050+ }
1051+ return sep ;
1052+ }
1053+
10461054 /**
10471055 * Escapes HTML special characters in a string to prevent injection.
10481056 */
0 commit comments