Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): strange click handling in checklists [M-5311] (#403)

Seamusf56d172bbe72
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index b0f88760ce..a77a2060f6 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -665,9 +665,20 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
});
});
- // better focus in handling. preserves selection on regain focus!
+ // HACK: We need to distinguish click-based focus events from programmatic
+ // ones (el.focus()). We want to maintain the previous selection (editor.focus)
+ // only if we are regaining focus programmatically. If click, let browser handle
+ // focus and let lexical catch up.
+ let clickFocusFlag = false;
autoRegister(
+ registerRootEventListener(editor, 'pointerdown', () => {
+ clickFocusFlag = true;
+ setTimeout(() => {
+ clickFocusFlag = false; // negate the flag after tasks
+ });
+ }),
registerRootEventListener(editor, 'focusin', (e) => {
+ if (clickFocusFlag) return;
e.preventDefault();
editor.focus(undefined, { defaultSelection: 'rootStart' });
})