Skip to content

Commit

Permalink
Fixed issue with appending lines in CSV files.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Juback committed Jan 12, 2022
1 parent bb403f1 commit c37cccb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
15 changes: 6 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Change Log

## 4.1.49 Pre-Release (January 7, 2022)
> This version supersedes 4.0.46 and 4.0.47, which were designated as pre-release but were not published correctly.
## 4.1.52 Pre-Release (January 12, 2022)
Fixed issue where new rows were not appended correctly if the CSV file did not end with a blank line.

Fixed issue where multilne cells in CSV files were rendered as single lines when a preview or custom editor was first displayed.

## 4.1.51 Pre-Release (January 7, 2022)
Fixed regression where the `Open Preview` command did not work with TSV files.

Added support for editing CSV files: modifying individual cells, deleting rows, and appending new rows.
Expand All @@ -11,15 +14,9 @@ Added support for editing Excel files: modifying individual cells, inserting row

Upgraded to use Wijmo build 5.20213.824.

## 4.0.48 (January 7, 2022)
## 4.0.50 (January 7, 2022)
Stable version, equivalent to 4.0.45.

## 4.0.47 Pre-Release (January 7, 2022)
> Please disregard this version.
## 4.0.46 Pre-Release (January 4, 2022)
> Please disregard this version.
## 4.0.45 (November 30, 2021)
Added read-only custom editor support. For Excel files, this is the default, and clicking the name of an Excel file in Explorer view opens the custom editor directly. For CSV files, this is optional, and executing the `Open With` command on the context menu prompts for the built-in or custom editor to be opened. The `Open Preview` command is still supported for both file types.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Version 4.0 also adds support for **Visual Studio Code for the Web**. To get sta
> As a result of the changes needed to support Visual Studio Code for the Web, persistent previews saved with earlier versions of Excel Viewer cannot be restored. When one of these webviews is activated, the extension displays a message to that effect and provides additional instructions.
## 📝 *Pre-Release: Editing Support*
Version 4.1.49 extends the custom editors introduced in the latest stable release to include preliminary support for editing CSV and Excel files.
Version 4.1.52 extends the custom editors introduced in the latest stable release to include preliminary support for editing CSV and Excel files.

## CSV Usage
For files with a .csv, .tsv, or .tab extension, use the explorer context menu or editor title menu to invoke the `Open Preview` command. The contents of the file will be displayed in a [FlexGrid](http://demos.wijmo.com/5/Angular/Explorer/Explorer/#/grid/intro) control, which supports sorting and filtering via its column headers. You can also use the `Open With` command on the explorer context menu to open a read-only custom editor, as shown here:
Expand Down
11 changes: 11 additions & 0 deletions out/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,27 @@ function initPage() {
}
}

var needRowResize = false;
var emptyRange = new wijmo.grid.CellRange(0, 0);

// http://jsfiddle.net/Wijmo5/2a20kqvr/
function autoSizeVisibleRows(flex, force) {
var rng = flex.viewRange;
needRowResize = rng.equals(emptyRange);
for (var r = rng.row; r <= rng.row2; r++) {
if (force || flex.rows[r].height == null) {
flex.autoSizeRow(r, false);
}
}
}

flex.updatedView.addHandler(function(s, e) {
if (needRowResize) {
autoSizeVisibleRows(s, true);
needRowResize = false;
}
});

flex.itemsSourceChanged.addHandler(function(s, e) {
applyState();
var resize = options.resizeColumns;
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": "View Excel spreadsheets and CSV files in Visual Studio Code and VS Code for the Web.",
"version": "4.1.51",
"version": "4.1.52",
"icon": "img/gc-excelviewer.png",
"publisher": "GrapeCity",
"license": "SEE LICENSE IN LICENSE.txt",
Expand Down
9 changes: 8 additions & 1 deletion src/csvDocumentView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { window, workspace, WebviewPanel, ExtensionContext, ViewColumn, WorkspaceEdit, Range, TextDocument, Position } from 'vscode';
import { window, workspace, WebviewPanel, ExtensionContext, ViewColumn, WorkspaceEdit, Range, TextDocument, Position, EndOfLine } from 'vscode';
import { URI } from 'vscode-uri';
import BaseDocumentView from './baseDocumentView';
import { documentViewManager } from './documentViewManager';
Expand Down Expand Up @@ -125,6 +125,13 @@ export default class CsvDocumentView extends BaseDocumentView {
let sep = options.separator;
let empty = sep.repeat(columns - 1);
let row = this._document.lineCount - 1;
let line = this._document.lineAt(row);

if (!line.isEmptyOrWhitespace) {
this.beginEdit();
this._wsEdit.insert(this.uri, line.range.end, this._document.eol === EndOfLine.CRLF ? "\r\n" : "\n");
row++;
}

this._currentRange = new Range(row, 0, row, 0);
this._currentRow = empty.split(new RegExp(options.separator));
Expand Down

0 comments on commit c37cccb

Please sign in to comment.