Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visible newlines to display value for Edit Data cells #24334

Merged
merged 9 commits into from
Sep 8, 2023
12 changes: 5 additions & 7 deletions src/sql/workbench/contrib/editData/browser/editDataGridPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class EditDataGridPanel extends GridParentComponent {
}
else if (Services.DBCellValue.isDBCellValue(value)) {
// If a cell is not edited and retrieved direct from the SQL server, it would be in the form of a DBCellValue.
// We use the DBCellValue's displayValue as the text value.
// We use the DBCellValue's cleaned displayValue as the text value.
returnVal = this.replaceLinebreaks(value.displayValue);
}
else if (typeof value === 'string') {
Expand Down Expand Up @@ -477,7 +477,7 @@ export class EditDataGridPanel extends GridParentComponent {
id: columnIndex,
name: escape(c.columnName),
field: columnIndex,
formatter: this.getColumnFormatter,
formatter: (row, cell, value, columnDef, dataContext) => this.getColumnFormatter(row, cell, value, columnDef, dataContext, self.newlinePattern),
isEditable: c.isUpdatable
};
}))
Expand Down Expand Up @@ -710,7 +710,6 @@ export class EditDataGridPanel extends GridParentComponent {
let sessionRowId = self.rowIdMappings[self.currentCell.row] !== undefined
? self.rowIdMappings[self.currentCell.row]
: self.currentCell.row;

let restoredValue = this.newlinePattern ? self.currentEditCellValue.replace(/\u0000/g, this.newlinePattern) : self.currentEditCellValue;
return self.dataService.updateCell(sessionRowId, self.currentCell.column - 1, restoredValue);
}).then(
Expand Down Expand Up @@ -1256,7 +1255,7 @@ export class EditDataGridPanel extends GridParentComponent {


/*Formatter for Column*/
private getColumnFormatter(row: number | undefined, cell: number | undefined, value: any, columnDef: any | undefined, dataContext: any | undefined): string {
private getColumnFormatter(row: number | undefined, cell: number | undefined, value: any, columnDef: any | undefined, dataContext: any | undefined, newlinePattern: string): string {
let valueToDisplay = '';
let cellClasses = 'grid-cell-value-container';
/* tslint:disable:no-null-keyword */
Expand All @@ -1273,8 +1272,6 @@ export class EditDataGridPanel extends GridParentComponent {
// If a cell is not edited and retrieved direct from the SQL server, it would be in the form of a DBCellValue.
// We use it's displayValue and remove newlines for display purposes only.
valueToDisplay = (value.displayValue + '');
valueToDisplay = valueToDisplay.replace(/(\r\n|\n|\r)/g, '\u0000');
valueToDisplay = escape(valueToDisplay.length > 250 ? valueToDisplay.slice(0, 250) + '...' : valueToDisplay);
}
else if (typeof value === 'string' || (value && value.text)) {
// Once a cell has been edited, the cell value will no longer be a DBCellValue until refresh.
Expand All @@ -1284,8 +1281,9 @@ export class EditDataGridPanel extends GridParentComponent {
} else {
valueToDisplay = value;
}
valueToDisplay = escape(valueToDisplay.length > 250 ? valueToDisplay.slice(0, 250) + '...' : valueToDisplay);
valueToDisplay = newlinePattern ? valueToDisplay.replace(/\u0000/g, newlinePattern) : valueToDisplay;
}
valueToDisplay = Services.getCellDisplayValue(valueToDisplay);
return '<span title="' + valueToDisplay + '" class="' + cellClasses + '">' + valueToDisplay + '</span>';
}
}