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

Commit

Permalink
Merge pull request #1 from philipparndt/issue-48
Browse files Browse the repository at this point in the history
Format under cursor causes loss of data. rpeshkov#48
  • Loading branch information
philipparndt authored Nov 22, 2020
2 parents cd824b4 + f70b3ed commit da8234e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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

0 comments on commit da8234e

Please sign in to comment.