Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Format under cursor causes loss of data. #48 #1

Merged
merged 3 commits into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ttMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MarkdownParser implements tt.Parser {

isSeparatorRow(text: string): boolean {
const cleaned = text.replace(/\s+/g, '');
return cleaned.startsWith('|-') || cleaned.startsWith('|:-');
return (cleaned.startsWith('|-') || cleaned.startsWith('|:-')) && cleaned.match(/^[:|-\s]+$/) ? true : false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ttOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class OrgParser implements tt.Parser {
}

isSeparatorRow(text: string): boolean {
return text.length > 1 && text[1] === horizontalSeparator;
return text.length > 1 && text[1] === horizontalSeparator && text.match(/^[+|-\s]+$/) ? true : false;;
}
}

Expand Down
34 changes: 34 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ function move(editor: vscode.TextEditor, line: number, col: number) {
}

suite('Commands', () => {
test('Regression: Format under cursor causes loss of data.', async () => {
const testCase =
`| A| B|
| -1| -1|`;
const expected =
`| A | B |
| -1 | -1 |`;

await inTextEditor({language: 'markdown', content: testCase}, async (editor, document) => {
await cfg.override({mode: cfg.Mode.Markdown});
move(editor, 0, 1);
await vscode.commands.executeCommand('text-tables.gotoNextCell');

assert.equal(document.getText(), expected);
});
});

test('Regression: Format under cursor causes loss of data (org).', async () => {
const testCase =
`|A|B|
|-1|-1|`;
const expected =
`| A | B |
| -1 | -1 |`;

await inTextEditor({language: 'markdown', content: testCase}, async (editor, document) => {
await cfg.override({mode: cfg.Mode.Org});
move(editor, 0, 1);
await vscode.commands.executeCommand('text-tables.gotoNextCell');

assert.equal(document.getText(), expected);
});
});

test('Test "Create table" for markdown', async () => {
const expectedResult = `| | |
| --- | --- |
Expand Down