Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Comment on lines +132 to +134
Copy link
Copy Markdown

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]]}}. Current onTodo callers 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

if (text) {
const formattedText = ` ${text
.replace(new RegExp("\\^", "g"), "\\^")
Expand Down Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 {{[[ARCHIVED]]}}, the keydown handler converts it to {{[[TODO]]}} via updateBlock but does NOT call onTodo(). This means user-configured "On Todo" append text, tag replacements, and other onTodo triggers are skipped for ARCHIVED→TODO transitions. This appears intentional (un-archiving is distinct from creating a new TODO), but it's a behavioral choice worth confirming with the author if "On Todo" settings should also fire when restoring from ARCHIVED state.

Open in Devin Review

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);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/normalizeTodoArchivedPrefix.ts
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;