Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
| export const lockToolIfNeeded = (editor: Editor): void => { | ||
| if (!editor.getInstanceState().isToolLocked) { | ||
| editor.updateInstanceState({ isToolLocked: true }); | ||
| } |
There was a problem hiding this comment.
🔴 lockToolIfNeeded unconditionally forces isToolLocked = true, overriding user preference
Every click on a tool in the DiscourseToolPanel calls lockToolIfNeeded(editor) before editor.setCurrentTool(...). This function unconditionally sets isToolLocked = true in the editor's global instance state whenever it's currently false.
Root Cause and Impact
The lockToolIfNeeded function at apps/roam/src/components/canvas/toolLock.ts:9-12 always forces isToolLocked to true:
export const lockToolIfNeeded = (editor: Editor): void => {
if (!editor.getInstanceState().isToolLocked) {
editor.updateInstanceState({ isToolLocked: true });
}
};This is called from DiscourseToolPanel.tsx:171 (panel click) and DiscourseToolPanel.tsx:198 (drag-drop relation). After this call, the global isToolLocked state is permanently set to true. This means:
- User has tool lock OFF (the default).
- User clicks any tool in the panel →
lockToolIfNeededsilently forcesisToolLocked = true. - Now all tools (including those activated via keyboard shortcuts at
apps/roam/src/components/canvas/uiOverrides.tsx:355,374,397) behave as locked, because the global state has been mutated. - The user's preference is permanently overridden with no way to know it happened, and they must manually toggle the lock off via the tldraw UI.
Impact: The user's tool lock preference is silently and permanently overridden after any panel interaction. This changes the behavior of all subsequent tool usage across the entire canvas.
Prompt for agents
The lockToolIfNeeded function in apps/roam/src/components/canvas/toolLock.ts unconditionally forces isToolLocked to true, which permanently overrides the user's preference. There are two possible fixes depending on the intended behavior:
1. If the intent is that panel clicks should NOT modify the lock state (just respect whatever the user has set): Remove lockToolIfNeeded entirely and remove its calls at apps/roam/src/components/canvas/DiscourseToolPanel.tsx lines 171 and 198. The setCurrentToolToSelectIfUnlocked already handles the unlocked case correctly.
2. If the intent is that panel clicks should temporarily lock the tool (so one click = one use): Save and restore the previous isToolLocked state. For example, set isToolLocked to true before setCurrentTool, and after the shape is created (in setCurrentToolToSelectIfUnlocked), restore the original value. This would require threading the original state through or storing it somewhere accessible.
Was this helpful? React with 👍 or 👎 to provide feedback.
Uh oh!
There was an error while loading. Please reload this page.