Skip to content

Commit

Permalink
Port of Maddy's Edit Data Line Fix (microsoft#10676)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartguest authored Jun 16, 2020
1 parent b922fc7 commit f13a595
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class EditDataGridPanel extends GridParentComponent {
private rowIdMappings: { [gridRowId: number]: number } = {};
private dirtyCells: number[] = [];
protected plugins = new Array<Slick.Plugin<any>>();
private newlinePattern: string;
// List of column names with their indexes stored.
private columnNameToIndex: { [columnNumber: number]: string } = {};
// Edit Data functions
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f13a595

Please sign in to comment.