Insert date while creating a checkbox#51
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a feature to automatically insert the current date when creating checkboxes, addressing issue #17. The feature adds a new configuration option to control this behavior and includes logic to prevent duplicate date insertion.
- Adds
dateWhenCreatedconfiguration setting (defaults to true) to enable/disable automatic date insertion - Modifies checkbox creation logic to include current date when enabled and no existing date is detected
- Implements date detection regex to prevent duplicate dates when converting existing content
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| package.json | Adds new dateWhenCreated boolean configuration option with default value true |
| src/createCheckbox.ts | Implements date insertion logic with duplicate detection using regex pattern |
| src/test/spec/defaultSettings.ts | Sets test default for dateWhenCreated to false |
| src/test/spec/checkbox/createCheckbox.spec.ts | Adds comprehensive tests for date insertion scenarios |
Comments suppressed due to low confidence (1)
src/createCheckbox.ts:25
- The variable name
hasDateis misleading since it actually checks for a specific date format at the beginning of the line, not just any date. Consider renaming tohasDatePrefixorstartsWithDatefor clarity.
const hasDate = helpers
| dateWhenChecked: true, | ||
| showStatusBarItem: true, | ||
| dateFormat: 'YYYY-MM-DD', | ||
| dateWhenCreated: false, |
There was a problem hiding this comment.
The test default for dateWhenCreated is set to false, but the package.json default is true. This inconsistency could lead to confusion and test scenarios that don't match the actual user experience. Consider aligning the test default with the production default.
| dateWhenCreated: false, | |
| dateWhenCreated: true, |
| const checkboxCharacters = '[ ] '; | ||
| const hasDate = helpers | ||
| .getPlainLineText(line.text) | ||
| .match(/^(?:[+*-]\s)?\d{4}-\d{2}-\d{2} /); |
There was a problem hiding this comment.
The hardcoded regex pattern /^(?:[+*-]\s)?\d{4}-\d{2}-\d{2} / assumes ISO date format, but the code ignores the dateFormat configuration. This creates inconsistency between date insertion and detection logic, potentially causing issues if users have different date formats configured.
dateWhenCreatedadded, defaults to true, to disable this feature.Notes:
I would like to remove the creation date if checked at the same day, and use the checked date for creation when reopen without a create date later. What do you think?