Skip to content

Commit

Permalink
Fixed CSV editing bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Juback committed Jun 13, 2022
1 parent c30fbb9 commit 7592049
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 4.2.55 (June 13, 2022)
Fixed issue with CSV editing where text pasted into a cell was ignored when saving the file.

Fixed issue with CSV editing where changing a value in the rightmost cell could result in extra line breaks and/or misaligned cells when saving the file.

Fixed issue where a line number was displayed instead of the `*` character in the AddNew row.

## 4.2.54 (March 29, 2022)
Fixed problems with CSV editing when the `csv-preview.separator` configuration setting was set to a regular expression instead of a single character.

Expand Down
33 changes: 25 additions & 8 deletions out/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ function initPage() {

flex.formatItem.addHandler(function(s, e) {
if (lineNumbers) {
if (e.panel.cellType == wijmo.grid.CellType.RowHeader) {
if (numbersSource) {
var row = flex.rows[e.row];
var source = flex.collectionView.sourceCollection;
var n = source.indexOf(row.dataItem) + 1;
e.cell.textContent = n.toString();
} else if (numbersOrdinal) {
e.cell.textContent = (e.row + 1).toString();
if (e.panel.cellType == wijmo.grid.CellType.RowHeader) {
var row = flex.rows[e.row];
if (!(row instanceof wijmo.grid._NewRowTemplate)) {
if (numbersSource) {
var source = flex.collectionView.sourceCollection;
var n = source.indexOf(row.dataItem) + 1;
e.cell.textContent = n.toString();
} else if (numbersOrdinal) {
e.cell.textContent = (e.row + 1).toString();
}
}
}
}
Expand Down Expand Up @@ -183,6 +185,21 @@ function initPage() {
}
});

flex.pastedCell.addHandler(function(s, e) {
var oldValue = e.data;
var newValue = s.getCellData(e.row, e.col);
if (oldValue !== newValue) {
var row = s.rows[e.row];
var source = s.collectionView.sourceCollection;
vscode.postMessage({
cellEditEnded: true,
row: source.indexOf(row.dataItem),
col: e.col,
value: newValue
});
}
});

flex.rowEditEnded.addHandler(function(s, e) {
vscode.postMessage({
rowEditEnded: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gc-excelviewer",
"displayName": "Excel Viewer",
"description": "Edit Excel spreadsheets and CSV files in Visual Studio Code and VS Code for the Web.",
"version": "4.2.54",
"version": "4.2.55",
"icon": "img/gc-excelviewer.png",
"publisher": "GrapeCity",
"license": "SEE LICENSE IN LICENSE.txt",
Expand Down
5 changes: 5 additions & 0 deletions src/csvDocumentView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export default class CsvDocumentView extends BaseDocumentView {

this._currentRange = new Range(row + offset, 0, row + offset + 1, 0);
let line = this._document.getText(this._currentRange);
let eol = this.endOfLine();

if (line.endsWith(eol)) {
line = line.substring(0, line.length - eol.length);
}

// http://markmintoff.com/2013/03/regex-split-by-comma-not-surrounded-by-quotes/
let regexItems = new RegExp(`${sep}(?=(?:[^${quote}]*${quote}[^${quote}]*${quote})*[^${quote}]*$)`);
Expand Down

0 comments on commit 7592049

Please sign in to comment.