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
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import getChildrenLengthByParentUid from "roamjs-components/queries/getChildrenL
import initializeTodont, { TODONT_MODES } from "./utils/todont";

export default runExtension(async ({ extensionAPI }) => {
const toggleTodont = initializeTodont();
const toggleTodont = initializeTodont(extensionAPI);
extensionAPI.settings.panel.create({
tabTitle: "TODO Trigger",
settings: [
Expand Down Expand Up @@ -83,7 +83,7 @@ export default runExtension(async ({ extensionAPI }) => {
id: "todont-mode",
name: "TODONT Mode",
description:
"Whether to incorporate styling when TODOS turn into ARCHIVED buttons.",
"Whether to incorporate styling when TODOS turn into ARCHIVED buttons. When enabled, adds 'Archive TODO' command to the command palette (customizable hotkey in Settings → Hotkeys).",
action: {
type: "select",
items: TODONT_MODES.slice(0),
Expand Down
29 changes: 16 additions & 13 deletions src/utils/todont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByPar
import createHTMLObserver from "roamjs-components/dom/createHTMLObserver";
import createObserver from "roamjs-components/dom/createObserver";
import toFlexRegex from "roamjs-components/util/toFlexRegex";
import isControl from "roamjs-components/util/isControl";
import getUids from "roamjs-components/dom/getUids";
import { OnloadArgs } from "roamjs-components/types";

Expand Down Expand Up @@ -82,9 +81,15 @@ export const replaceText = ({

export const TODONT_MODES = ["off", "icon", "strikethrough"] as const;

const initializeTodont = () => {
const ARCHIVE_COMMAND_LABEL = "Archive TODO";

const initializeTodont = (extensionAPI: OnloadArgs["extensionAPI"]) => {
const unloads = new Set<() => void>();
return async (todontMode: typeof TODONT_MODES[number]) => {
// Clean up previous mode before setting up new one
unloads.forEach((u) => u());
unloads.clear();

if (todontMode !== "off") {
const TODONT_CLASSNAME = "roamjs-todont";
const css = document.createElement("style");
Expand Down Expand Up @@ -197,15 +202,16 @@ const initializeTodont = () => {
}
};

const keydownEventListener = async (e: KeyboardEvent) => {
if (e.key === "Enter" && e.shiftKey && isControl(e)) {
todontCallback();
}
};

document.addEventListener("keydown", keydownEventListener);
extensionAPI.ui.commandPalette.addCommand({
label: ARCHIVE_COMMAND_LABEL,
callback: todontCallback,
"default-hotkey": "ctrl-shift-enter",
"disable-hotkey": false,
});
Comment on lines +205 to +210
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -n "commandPalette\.addCommand" -A 5 -B 2

Repository: RoamJS/todo-trigger

Length of output: 961


🏁 Script executed:

rg -n "default-hotkey|disable-hotkey" -B 3 -A 3

Repository: RoamJS/todo-trigger

Length of output: 546


🏁 Script executed:

rg -n "ctrl-|shift-|meta-" -i --type ts --type js | head -20

Repository: RoamJS/todo-trigger

Length of output: 132


🏁 Script executed:

find . -name "*.d.ts" -o -name "README*" -o -name "*roam*" -type f | grep -v node_modules | head -20

Repository: RoamJS/todo-trigger

Length of output: 74


🏁 Script executed:

cat package.json | grep -A 5 -B 5 roam

Repository: RoamJS/todo-trigger

Length of output: 549


🏁 Script executed:

rg -n "roamAlphaAPI|roam.*API" -i | head -30

Repository: RoamJS/todo-trigger

Length of output: 1110


🏁 Script executed:

find . -path "*/roamjs-components/*" -name "*.d.ts" | head -20

Repository: RoamJS/todo-trigger

Length of output: 45


🏁 Script executed:

grep -r "commandPalette" . --include="*.d.ts" 2>/dev/null | head -20

Repository: RoamJS/todo-trigger

Length of output: 45


🏁 Script executed:

head -100 README.md

Repository: RoamJS/todo-trigger

Length of output: 3738


🌐 Web query:

Roam Research command palette hotkey format ctrl shift enter API documentation

💡 Result:

Use a plus-separated, lowercase modifier+key string (e.g. "ctrl+shift+enter" or "command+shift+p"). Libraries and apps that Roam integrations use follow this format (modifiers first, joined with "+", then the key). Examples: "ctrl+shift+enter", "ctrl+shift+p". [1][2]

Sources:

  • Roam shortcut listings showing modifier+key notation. [1]
  • npm command-palette component (hotKeys default format "command+shift+p"). [2]
  • TestCafe / common tooling examples using "ctrl+shift+enter" style. [3]

References:
[1] Roam Research keyboard shortcuts (cheatsheet).
[2] @folk-org/react-command-palette (npm) — hotKeys format example.
[3] TestCafe / Stack Overflow example using 'ctrl+shift+enter'.


Fix the hotkey format: use plus signs instead of hyphens.

The hotkey should be "ctrl+shift+enter" not "ctrl-shift-enter". The README documents this for users as "CMD+SHIFT+ENTER (CTRL in windows)", and standard keyboard shortcut notation uses plus signs (+) to separate modifiers and keys. The current hyphen-separated format will likely fail to register the hotkey properly.

🤖 Prompt for AI Agents
In src/utils/todont.ts around lines 201 to 206 the command palette hotkey is
using hyphens ("ctrl-shift-enter") which is incorrect; update the
"default-hotkey" value to use plus signs ("ctrl+shift+enter") so the
modifier/key format matches the README and will register correctly in the UI;
keep the rest of the command object unchanged.

unloads.add(() => {
document.removeEventListener("keydown", keydownEventListener);
extensionAPI.ui.commandPalette.removeCommand({
label: ARCHIVE_COMMAND_LABEL,
});
});

if (todontMode === "strikethrough") {
Expand Down Expand Up @@ -235,9 +241,6 @@ const initializeTodont = () => {
});
unloads.add(() => strikethroughObserver.disconnect());
}
} else {
unloads.forEach((u) => u());
unloads.clear();
}
};
};
Expand Down