diff --git a/src/ttMarkdown.ts b/src/ttMarkdown.ts index d7607e7..05ee76c 100644 --- a/src/ttMarkdown.ts +++ b/src/ttMarkdown.ts @@ -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; } } diff --git a/src/ttOrg.ts b/src/ttOrg.ts index 4376be0..4f68c2b 100644 --- a/src/ttOrg.ts +++ b/src/ttOrg.ts @@ -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;; } } diff --git a/test/commands.test.ts b/test/commands.test.ts index 224c525..e4022ea 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -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 = `| | | | --- | --- |