diff --git a/src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts b/src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts index 2308a333cc..b4b6e1b30b 100644 --- a/src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts +++ b/src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts @@ -66,6 +66,7 @@ export class EditDataGridPanel extends GridParentComponent { private rowIdMappings: { [gridRowId: number]: number } = {}; private dirtyCells: number[] = []; protected plugins = new Array>(); + private newlinePattern: string; // List of column names with their indexes stored. private columnNameToIndex: { [columnNumber: number]: string } = {}; // Edit Data functions @@ -190,10 +191,10 @@ export class EditDataGridPanel extends GridParentComponent { returnVal = null; } else if (Services.DBCellValue.isDBCellValue(value)) { - returnVal = this.spacefyLinebreaks(value.displayValue); + returnVal = this.replaceLinebreaks(value.displayValue); } else if (typeof value === 'string') { - returnVal = this.spacefyLinebreaks(value); + returnVal = this.replaceLinebreaks(value); } return returnVal; }; @@ -431,8 +432,12 @@ export class EditDataGridPanel extends GridParentComponent { /** * Replace the line breaks with space. */ - private spacefyLinebreaks(inputStr: string): string { - return inputStr.replace(/(\r\n|\n|\r)/g, ' '); + private replaceLinebreaks(inputStr: string): string { + let newlineMatches = inputStr.match(/(\r\n|\n|\r)/g); + if (newlineMatches && newlineMatches.length > 0) { + this.newlinePattern = newlineMatches[0]; + } + return inputStr.replace(/(\r\n|\n|\r)/g, '\u0000'); } private refreshGrid(): Thenable { @@ -575,7 +580,7 @@ export class EditDataGridPanel extends GridParentComponent { ? self.rowIdMappings[self.currentCell.row] : self.currentCell.row; - return self.dataService.updateCell(sessionRowId, self.currentCell.column - 1, self.currentEditCellValue); + return self.dataService.updateCell(sessionRowId, self.currentCell.column - 1, this.newlinePattern ? self.currentEditCellValue.replace('\u0000', this.newlinePattern) : self.currentEditCellValue); }).then( result => { self.currentEditCellValue = undefined;