-
Notifications
You must be signed in to change notification settings - Fork 2
Fix ARCHIVED → TODO transition on Cmd/Ctrl+Enter #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import extractRef from "roamjs-components/util/extractRef"; | |
| import extractTag from "roamjs-components/util/extractTag"; | ||
| import getChildrenLengthByParentUid from "roamjs-components/queries/getChildrenLengthByParentUid"; | ||
| import initializeTodont, { TODONT_MODES } from "./utils/todont"; | ||
| import normalizeTodoArchivedPrefix from "./utils/normalizeTodoArchivedPrefix"; | ||
|
|
||
| export default runExtension(async ({ extensionAPI }) => { | ||
| const toggleTodont = initializeTodont(); | ||
|
|
@@ -128,6 +129,9 @@ export default runExtension(async ({ extensionAPI }) => { | |
| } | ||
| const text = extensionAPI.settings.get("append-text") as string; | ||
| let value = oldValue; | ||
| // Roam's Cmd/Ctrl+Enter prepends TODO for non-checkbox blocks. | ||
| // If the block starts with ARCHIVED, collapse TODO+ARCHIVED into TODO. | ||
| value = normalizeTodoArchivedPrefix(value); | ||
| if (text) { | ||
| const formattedText = ` ${text | ||
| .replace(new RegExp("\\^", "g"), "\\^") | ||
|
|
@@ -352,7 +356,25 @@ export default runExtension(async ({ extensionAPI }) => { | |
| if (target.tagName === "TEXTAREA") { | ||
| const textArea = target as HTMLTextAreaElement; | ||
| const { blockUid } = getUids(textArea); | ||
| if (textArea.value.startsWith("{{[[DONE]]}}")) { | ||
| // Check data layer for ARCHIVED state — the textarea DOM value | ||
| // may lag behind after a recent API update. | ||
| const blockText = | ||
| getTextByBlockUid(blockUid) || textArea.value; | ||
| if (blockText.startsWith("{{[[ARCHIVED]]}}")) { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| e.stopImmediatePropagation(); | ||
| const withoutArchived = blockText.replace( | ||
| /^\{\{\[\[ARCHIVED\]\]\}}\s*/, | ||
| "", | ||
| ); | ||
| const normalized = withoutArchived | ||
| ? `{{[[TODO]]}} ${withoutArchived}` | ||
| : "{{[[TODO]]}}"; | ||
| if (normalized !== blockText) { | ||
| updateBlock({ uid: blockUid, text: normalized }); | ||
| } | ||
|
Comment on lines
+363
to
+376
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 ARCHIVED→TODO transition does not trigger onTodo settings When a block starts with Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } else if (textArea.value.startsWith("{{[[DONE]]}}")) { | ||
| onDone(blockUid, textArea.value); | ||
| } else if (textArea.value.startsWith("{{[[TODO]]}}")) { | ||
| onTodo(blockUid, textArea.value); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const TODO_ARCHIVED_PREFIX_REGEX = | ||
| /^(\{\{\[\[TODO\]\]\}})\s*\{\{\[\[ARCHIVED\]\]\}}/; | ||
|
|
||
| const normalizeTodoArchivedPrefix = (value: string): string => | ||
| value.replace(TODO_ARCHIVED_PREFIX_REGEX, "$1"); | ||
|
|
||
| export default normalizeTodoArchivedPrefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 normalizeTodoArchivedPrefix is unlikely to match in current onTodo call sites
The normalization regex
/^(\{\{\[\[TODO\]\]\}\})\s*\{\{\[\[ARCHIVED\]\]\}\}/requires text to start with{{[[TODO]]}}followed by{{[[ARCHIVED]]}}. CurrentonTodocallers pass text starting with{{[[DONE]]}}(keydown handler line 378), post-toggle text from checkbox click (line 318), or textarea value from click listener (line 345). None of these would typically produce a{{[[TODO]]}}{{[[ARCHIVED]]}}prefix. The normalization acts as a defensive guard but may never match in practice. Consider whether there's an actual code path that produces this pattern, or if the normalization should be placed elsewhere.Was this helpful? React with 👍 or 👎 to provide feedback.