From 7cca1b9f486ab7bc49d686ecb8cd4739ff5244c1 Mon Sep 17 00:00:00 2001 From: Maddy <12754347+MaddyDev@users.noreply.github.com> Date: Mon, 6 May 2019 14:20:08 -0700 Subject: [PATCH] Maddy/newline overrides edit data (#5364) * formatting it before displaying * replace with space * added comments and method to handle the line break space conversion --- .../parts/grid/views/editData/editData.component.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/parts/grid/views/editData/editData.component.ts b/src/sql/workbench/parts/grid/views/editData/editData.component.ts index 5a65e9be5d..567b43e1f9 100644 --- a/src/sql/workbench/parts/grid/views/editData/editData.component.ts +++ b/src/sql/workbench/parts/grid/views/editData/editData.component.ts @@ -177,10 +177,12 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On this.overrideCellFn = (rowNumber, columnId, value?, data?): string => { let returnVal = ''; + // replace the line breaks with space since the edit text control cannot + // render line breaks and strips them, updating the value. if (Services.DBCellValue.isDBCellValue(value)) { - returnVal = value.displayValue; + returnVal = this.spacefyLinebreaks(value.displayValue); } else if (typeof value === 'string') { - returnVal = value; + returnVal = this.spacefyLinebreaks(value); } return returnVal; }; @@ -406,6 +408,13 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On this.refreshGrid(); } + /** + * Replace the line breaks with space. + */ + private spacefyLinebreaks(inputStr: string): string { + return inputStr.replace(/(\r\n|\n|\r)/g, ' '); + } + private refreshGrid(): Thenable { return new Promise((resolve, reject) => { const self = this;