Skip to content

Commit

Permalink
Fix: existing bullet point causes duplicates (PKief#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganskef committed May 12, 2023
1 parent c97257e commit 1699007
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/createCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const createCheckboxOfLine = (
const checkboxOfLine = helpers.getCheckboxOfLine(line);
const hasDate = helpers
.getPlainLineText(line.text)
.match(/^\d{4}-\d{2}-\d{2} /);
.match(/^(?:[+*-]\s)?\d{4}-\d{2}-\d{2} /);
const checkboxCharacters =
dateWhenCreated && !hasDate ? `[ ] ${dateNow} ` : '[ ] ';

Expand Down
33 changes: 32 additions & 1 deletion src/test/spec/checkbox/createCheckbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('create checkboxes', () => {
assert.strictEqual(content, expectedResult);
});

it('should not insert creation date twice if exists', async () => {
it('should not insert another creation date', async () => {
// create new document
const newDocument = await vscode.workspace.openTextDocument({
content: '9999-99-99 this is a text',
Expand Down Expand Up @@ -205,4 +205,35 @@ describe('create checkboxes', () => {

assert.strictEqual(content, expectedResult);
});

it('should not insert another creation date with existing bullet', async () => {
// create new document
const newDocument = await vscode.workspace.openTextDocument({
content: '- 9999-99-99 this is a text',
language: 'markdown',
});
await vscode.window.showTextDocument(newDocument);

// update config to insert creation date if configured
await vscode.workspace
.getConfiguration('markdown-checkbox')
.update('dateWhenCreated', true);

// set the cursor to the current line
const editor = getEditor();
const position = editor.selection.active;
const newCursorPosition = position.with(0, 0);
const newSelection = new vscode.Selection(
newCursorPosition,
newCursorPosition
);
editor.selection = newSelection;

await createCheckbox(editor);

const content = editor.document.getText();
const expectedResult = `- [ ] 9999-99-99 this is a text`;

assert.strictEqual(content, expectedResult);
});
});

0 comments on commit 1699007

Please sign in to comment.