-
Notifications
You must be signed in to change notification settings - Fork 2
Fix TODO state detection and prevent duplicate triggers #18
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
Open
salmonumbrella
wants to merge
6
commits into
RoamJS:main
Choose a base branch
from
salmonumbrella:fix/todo-state-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
00ab2b9
fix: normalize TODO+ARCHIVED prefix on Cmd/Ctrl+Enter
salmonumbrella 5021d77
fix: improve TODO state detection and prevent duplicate triggers
salmonumbrella 5b89cd5
fix: address todo state review notes
salmonumbrella e483f1e
fix: avoid duplicate todo state triggers after keyboard toggles
salmonumbrella 252487b
fix: widen clickListener param to Event for domListeners type compat
salmonumbrella 65e3c8f
fix: revert TODO/DONE toggle to read textarea value synchronously
salmonumbrella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| export type TodoState = "todo" | "done" | "other"; | ||
|
|
||
| export const getTodoState = (value: string): TodoState => { | ||
| if (value.startsWith("{{[[DONE]]}}")) { | ||
| return "done"; | ||
| } | ||
| if (value.startsWith("{{[[TODO]]}}")) { | ||
| return "todo"; | ||
| } | ||
| return "other"; | ||
| }; | ||
|
|
||
| export const captureInitialTodoState = ( | ||
| trackedStates: Map<string, TodoState>, | ||
| blockUid: string, | ||
| value: string, | ||
| ): void => { | ||
| trackedStates.set(blockUid, getTodoState(value)); | ||
| }; | ||
|
|
||
| export const markHandledTodoState = ( | ||
| trackedStates: Map<string, TodoState>, | ||
| blockUid: string, | ||
| value: string, | ||
| ): void => { | ||
| trackedStates.set(blockUid, getTodoState(value)); | ||
| }; | ||
|
|
||
| export const shouldHandleManualDoneOnFocusout = ( | ||
| initialState: TodoState | undefined, | ||
| value: string, | ||
| ): boolean => (initialState || "other") === "other" && getTodoState(value) === "done"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
| import { | ||
| captureInitialTodoState, | ||
| getTodoState, | ||
| markHandledTodoState, | ||
| shouldHandleManualDoneOnFocusout, | ||
| } from "../src/utils/todoStateTracking.ts"; | ||
|
|
||
| test("getTodoState classifies todo prefixes", () => { | ||
| assert.equal(getTodoState("{{[[TODO]]}} task"), "todo"); | ||
| assert.equal(getTodoState("{{[[DONE]]}} task"), "done"); | ||
| assert.equal(getTodoState("plain task"), "other"); | ||
| }); | ||
|
|
||
| test("handled keyboard toggles update tracked state", () => { | ||
| const trackedStates = new Map(); | ||
| captureInitialTodoState(trackedStates, "abc", "plain task"); | ||
|
|
||
| markHandledTodoState(trackedStates, "abc", "{{[[DONE]]}} task"); | ||
|
|
||
| assert.equal(trackedStates.get("abc"), "done"); | ||
| assert.equal( | ||
| shouldHandleManualDoneOnFocusout( | ||
| trackedStates.get("abc"), | ||
| "{{[[DONE]]}} task", | ||
| ), | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("focusout still fires for untouched other to done edits", () => { | ||
| const trackedStates = new Map(); | ||
| captureInitialTodoState(trackedStates, "abc", "plain task"); | ||
|
|
||
| assert.equal( | ||
| shouldHandleManualDoneOnFocusout( | ||
| trackedStates.get("abc"), | ||
| "{{[[DONE]]}} task", | ||
| ), | ||
| true, | ||
| ); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.