Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(md): md commands in command+k, cleanup format menu styles, clean up drag insert grabber (#2606)
Seamus0570e1ddfe10
diff --git a/js/app/packages/block-md/component/FormatTools.tsx b/js/app/packages/block-md/component/FormatTools.tsxindex 98f55047a8..810ff0e327 100644--- a/js/app/packages/block-md/component/FormatTools.tsx+++ b/js/app/packages/block-md/component/FormatTools.tsx@@ -449,17 +449,16 @@ export function FormatTools(props: { withinPopup?: boolean }) {const [menuOpen, setMenuOpen] = createSignal(false);return (<DropdownMenu open={menuOpen()} onOpenChange={setMenuOpen}>- <DropdownMenu.Trigger>- <Button- variant="ghost"- size="icon-sm"- class="rounded-xs"- tooltip={'Text Styles'}- disabled={buttonIsDisabled()}- tabIndex={-1}- >- <TextAA />- </Button>+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="rounded-xs"+ tooltip={'Text Styles'}+ disabled={buttonIsDisabled()}+ tabIndex={-1}+ >+ <TextAA /></DropdownMenu.Trigger><DropdownMenu.Portal><DropdownMenuContent@@ -514,17 +513,16 @@ export function FormatTools(props: { withinPopup?: boolean }) {const [menuOpen, setMenuOpen] = createSignal(false);return (<DropdownMenu open={menuOpen()} onOpenChange={setMenuOpen}>- <DropdownMenu.Trigger>- <Button- variant="ghost"- size="icon-sm"- class="rounded-xs"- tooltip="Text Styles"- disabled={props.buttonIsDisabled()}- tabIndex={-1}- >- <TextAA />- </Button>+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="rounded-xs"+ tooltip="Text Styles"+ disabled={props.buttonIsDisabled()}+ tabIndex={-1}+ >+ <TextAA /></DropdownMenu.Trigger><Show when={!props.buttonIsDisabled()}><DropdownMenu.Portal>@@ -566,17 +564,16 @@ export function FormatTools(props: { withinPopup?: boolean }) {buttonIsDisabled: Accessor<boolean>;}) => (<DropdownMenu>- <DropdownMenu.Trigger>- <Button- variant="ghost"- size="icon-sm"- class="rounded-xs"- tooltip={props.label ?? 'More Formats'}- disabled={buttonIsDisabled()}- tabIndex={-1}- >- <Dynamic component={props.icon ?? ThreeDots} />- </Button>+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="rounded-xs"+ tooltip={props.label ?? 'More Formats'}+ disabled={buttonIsDisabled()}+ tabIndex={-1}+ >+ <Dynamic component={props.icon ?? ThreeDots} /></DropdownMenu.Trigger><Show when={!buttonIsDisabled()}><DropdownMenu.Portal>@@ -613,17 +610,16 @@ export function FormatTools(props: { withinPopup?: boolean }) {buttonIsDisabled: Accessor<boolean>;}) => (<DropdownMenu>- <DropdownMenu.Trigger>- <Button- variant="ghost"- size="icon-sm"- class="rounded-xs"- tooltip={props.label ?? 'More Formats'}- disabled={buttonIsDisabled()}- tabIndex={-1}- >- <Dynamic component={props.icon ?? ThreeDots} />- </Button>+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="rounded-xs"+ tooltip={props.label ?? 'More Formats'}+ disabled={buttonIsDisabled()}+ tabIndex={-1}+ >+ <Dynamic component={props.icon ?? ThreeDots} /></DropdownMenu.Trigger><Show when={!buttonIsDisabled()}><DropdownMenu.Portal>@@ -665,7 +661,7 @@ export function FormatTools(props: { withinPopup?: boolean }) {if (props.withinPopup) {return (- <div class="flex h-full gap-1">+ <div class="flex h-full gap-1 items-center"><Show when={canEdit()}><ElementFormatButtonformat="paragraph"@@ -901,17 +897,16 @@ export function FormatTools(props: { withinPopup?: boolean }) {open={moreOptionsOpen()}onOpenChange={setMoreOptionsOpen}>- <DropdownMenu.Trigger>- <Button- variant="ghost"- size="icon-sm"- class="rounded-xs"- tooltip="More"- disabled={buttonIsDisabled()}- tabIndex={-1}- >- <PlusSquare />- </Button>+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="rounded-xs"+ tooltip="More"+ disabled={buttonIsDisabled()}+ tabIndex={-1}+ >+ <PlusSquare /></DropdownMenu.Trigger><Show when={!buttonIsDisabled()}><DropdownMenu.Portal>diff --git a/js/app/packages/block-md/component/MarkdownPopup.tsx b/js/app/packages/block-md/component/MarkdownPopup.tsxindex 367d4271ae..9fcbe83480 100644--- a/js/app/packages/block-md/component/MarkdownPopup.tsx+++ b/js/app/packages/block-md/component/MarkdownPopup.tsx@@ -423,7 +423,7 @@ export function MarkdownPopup(props: {</Show><Buttonsize="sm"- class="px-2 text-xs rounded-xs py-1.5"+ class="px-2 text-xs rounded-xs py-1.25"variant="ghost"onClick={async () => {const location = editor.read(() =>diff --git a/js/app/packages/block-md/component/Notebook.tsx b/js/app/packages/block-md/component/Notebook.tsxindex 62b4dedfdf..d3bd160ba8 100644--- a/js/app/packages/block-md/component/Notebook.tsx+++ b/js/app/packages/block-md/component/Notebook.tsx@@ -11,6 +11,8 @@ import { useBlockId } from '@core/block';import { ENABLE_MARKDOWN_COMMENTS } from '@core/constant/featureFlags';import { registerHotkey } from '@core/hotkey/hotkeys';import { TOKENS } from '@core/hotkey/tokens';+import { editorFocusSignal } from '@core/component/LexicalMarkdown/utils';+import { registerMarkdownCommands } from './useMarkdownCommands';import {blockElementSignal,blockHotkeyScopeSignal,@@ -179,6 +181,23 @@ export function Notebook() {);});+ // Register markdown formatting commands on the block scope so they appear in+ // Cmd+K, but only when the editor has focus (not just the block container).+ const [editorHasFocus, setEditorHasFocus] = createSignal(false);+ createEffect(() => {+ const editor = md.editor;+ if (!editor) return;+ const cleanup = editorFocusSignal(editor, setEditorHasFocus);+ onCleanup(cleanup);+ });+ createEffect(() => {+ if (!scopeId()) return;+ const group = untrack(() =>+ registerMarkdownCommands(scopeId(), () => md.editor, editorHasFocus)+ );+ onCleanup(() => group.dispose());+ });+// In preview mode, switching between Soup tabs was causing this createEffect to overflow the stack. We should figure out that root cause, this flag fixes it for now.let hasRun = false;createEffect(() => {diff --git a/js/app/packages/block-md/component/useMarkdownCommands.ts b/js/app/packages/block-md/component/useMarkdownCommands.tsnew file mode 100644index 0000000000..8ccaf5ab3a--- /dev/null+++ b/js/app/packages/block-md/component/useMarkdownCommands.ts@@ -0,0 +1,165 @@+import { ACTIONS } from '@core/component/LexicalMarkdown/plugins/actions/actions';+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';+import { TOKENS } from '@core/hotkey/tokens';+import type { HotkeyToken } from '@core/hotkey/tokens';+import type { ValidHotkey } from '@core/hotkey/types';+import TextBold from '@icon/bold/text-b-bold.svg';+import TextCode from '@icon/regular/code.svg';+import TextHighlight from '@icon/regular/paint-roller.svg';+import TextItalic from '@icon/regular/text-italic.svg';+import TextStrikethrough from '@icon/regular/text-strikethrough.svg';+import TextSub from '@icon/regular/text-subscript.svg';+import TextSuper from '@icon/regular/text-superscript.svg';+import TextUnderline from '@icon/regular/text-underline.svg';+import {+ FORMAT_TEXT_COMMAND,+ type LexicalEditor,+ type TextFormatType,+} from 'lexical';+import type { Component, JSX } from 'solid-js';++type InlineFormatDef = {+ token: HotkeyToken;+ format: TextFormatType;+ description: string;+ icon: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;+ hotkey?: ValidHotkey;+};++const INLINE_FORMATS: InlineFormatDef[] = [+ {+ token: TOKENS.md.bold,+ format: 'bold',+ description: 'Bold',+ icon: TextBold,+ hotkey: 'cmd+b',+ },+ {+ token: TOKENS.md.italic,+ format: 'italic',+ description: 'Italic',+ icon: TextItalic,+ hotkey: 'cmd+i',+ },+ {+ token: TOKENS.md.underline,+ format: 'underline',+ description: 'Underline',+ icon: TextUnderline,+ hotkey: 'cmd+u',+ },+ {+ token: TOKENS.md.strikethrough,+ format: 'strikethrough',+ description: 'Strikethrough',+ icon: TextStrikethrough,+ hotkey: 'shift+cmd+x',+ },+ {+ token: TOKENS.md.highlight,+ format: 'highlight',+ description: 'Highlight',+ icon: TextHighlight,+ hotkey: 'shift+cmd+h',+ },+ {+ token: TOKENS.md.inlineCode,+ format: 'code',+ description: 'Inline code',+ icon: TextCode,+ hotkey: 'cmd+e',+ },+ {+ token: TOKENS.md.superscript,+ format: 'superscript',+ description: 'Superscript',+ icon: TextSuper,+ },+ {+ token: TOKENS.md.subscript,+ format: 'subscript',+ description: 'Subscript',+ icon: TextSub,+ },+];++// -- Map ACTIONS ids to hotkey tokens ---------------------------------------++const ACTION_ID_TO_TOKEN: Record<string, HotkeyToken> = {+ paragraph: TOKENS.md.paragraph,+ heading1: TOKENS.md.heading1,+ heading2: TOKENS.md.heading2,+ heading3: TOKENS.md.heading3,+ quote: TOKENS.md.quote,+ code: TOKENS.md.codeBlock,+ 'list-bullet': TOKENS.md.bulletList,+ 'list-number': TOKENS.md.numberedList,+ 'list-check': TOKENS.md.checklist,+ image: TOKENS.md.image,+ video: TOKENS.md.video,+ link: TOKENS.md.link,+ latex: TOKENS.md.math,+ table: TOKENS.md.table,+ hr: TOKENS.md.divider,+};++/**+ * Registers markdown formatting commands on the block hotkey scope so they+ * appear in the command menu (Cmd+K). Inline formats that already have+ * Lexical-owned keyboard shortcuts use `proxiedHotkey` -- the hotkey system+ * displays them but lets Lexical handle the actual keystroke; only command-menu+ * invocation runs the handler.+ *+ * Block-level and insertion commands reuse the ACTIONS definitions from the+ * slash-command system.+ */+export function registerMarkdownCommands(+ scopeId: string,+ getEditor: () => LexicalEditor | undefined,+ condition?: () => boolean+) {+ const group = createHotkeyGroup();+ const hide = condition ? () => !condition() : undefined;+ const shared = { scopeId, hide, runWithInputFocused: true } as const;++ // Inline text formats (bold, italic, etc.)+ for (const def of INLINE_FORMATS) {+ registerHotkey({+ ...shared,+ hotkeyToken: def.token,+ hotkey: def.hotkey,+ description: def.description,+ icon: def.icon,+ proxiedHotkey: !!def.hotkey,+ keyDownHandler: () => {+ const editor = getEditor();+ if (!editor) return false;+ editor.dispatchCommand(FORMAT_TEXT_COMMAND, def.format);+ editor.focus();+ return true;+ },+ }).withGroup(group);+ }++ // Block-level transforms & insertions (from slash-command ACTIONS)+ for (const action of ACTIONS) {+ const token = ACTION_ID_TO_TOKEN[action.id];+ if (!token) continue;++ registerHotkey({+ ...shared,+ hotkeyToken: token,+ description: action.name,+ icon: action.icon,+ keyDownHandler: () => {+ const editor = getEditor();+ if (!editor) return false;+ action.action(editor);+ editor.focus();+ return true;+ },+ }).withGroup(group);+ }++ return group;+}diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/draggable-block/draggableBlockPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/draggable-block/draggableBlockPlugin.tsindex 4fb75677e9..f57956fdaf 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/draggable-block/draggableBlockPlugin.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/draggable-block/draggableBlockPlugin.ts@@ -9,8 +9,11 @@ import {$getNearestNodeFromDOMNode,$getNodeByKey,$getRoot,+ $getSelection,+ $isRangeSelection,COMMAND_PRIORITY_HIGH,KEY_DOWN_COMMAND,+ SELECTION_CHANGE_COMMAND,type LexicalEditor,} from 'lexical';import { createStore, type SetStoreFunction } from 'solid-js/store';@@ -228,6 +231,7 @@ function registerDraggableBlock(const { setState } = props;let isDraggingBlock = false;let isKeyboardMode = false;+ let hasNonCollapsedSelection = false;let rafId: number | null = null;let latestMouseEvent: MouseEvent | null = null;@@ -245,6 +249,12 @@ function registerDraggableBlock(// Ignore mouse-moves while a button is held (text selection, etc.)if (event.buttons > 0) return;+ // Hide drag menu if there's a non-collapsed range selection+ if (hasNonCollapsedSelection) {+ clearHover();+ return;+ }+// Keep the current hover while the cursor sits on the drag handle itself.if (target.closest('.draggable-block-menu')) return;@@ -536,6 +546,21 @@ function registerDraggableBlock(COMMAND_PRIORITY_HIGH);+ // Hide drag handle when there's a non-collapsed selection+ const unregisterSelectionChange = editor.registerCommand(+ SELECTION_CHANGE_COMMAND,+ () => {+ const selection = $getSelection();+ hasNonCollapsedSelection =+ $isRangeSelection(selection) && !selection.isCollapsed();+ if (hasNonCollapsedSelection) {+ clearHover();+ }+ return false;+ },+ COMMAND_PRIORITY_HIGH+ );+function cleanup() {if (rafId !== null) {cancelAnimationFrame(rafId);@@ -544,6 +569,7 @@ function registerDraggableBlock(document.removeEventListener('mousemove', onMouseMove);window.removeEventListener('scroll', onScroll, true);unregisterKeyDown();+ unregisterSelectionChange();}if (props.anchorElem) {diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.tsindex 643319bc8a..18af8c62da 100644--- a/js/app/packages/core/hotkey/hotkeys.ts+++ b/js/app/packages/core/hotkey/hotkeys.ts@@ -125,6 +125,7 @@ export function registerHotkey(icon,tags,shouldReturnFocusOnClose,+ proxiedHotkey,} = args;const noopDisposer: RegisterHotkeyReturn = {@@ -227,6 +228,7 @@ export function registerHotkey(icon,tags,shouldReturnFocusOnClose,+ proxiedHotkey,};// Check for existing hotkeys in the scope and warn if overridingdiff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.tsindex 193b6e6998..0e864d86b5 100644--- a/js/app/packages/core/hotkey/tokens.ts+++ b/js/app/packages/core/hotkey/tokens.ts@@ -178,6 +178,33 @@ export const TOKENS = {},},+ // markdown editor+ md: {+ bold: 'md.bold',+ italic: 'md.italic',+ underline: 'md.underline',+ strikethrough: 'md.strikethrough',+ highlight: 'md.highlight',+ inlineCode: 'md.inlineCode',+ superscript: 'md.superscript',+ subscript: 'md.subscript',+ heading1: 'md.heading1',+ heading2: 'md.heading2',+ heading3: 'md.heading3',+ paragraph: 'md.paragraph',+ quote: 'md.quote',+ codeBlock: 'md.codeBlock',+ bulletList: 'md.bulletList',+ numberedList: 'md.numberedList',+ checklist: 'md.checklist',+ link: 'md.link',+ image: 'md.image',+ video: 'md.video',+ math: 'md.math',+ table: 'md.table',+ divider: 'md.divider',+ },+// create menucreate: {note: 'create.note',diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.tsindex 3a19fa1309..36562ebd19 100644--- a/js/app/packages/core/hotkey/types.ts+++ b/js/app/packages/core/hotkey/types.ts@@ -51,6 +51,14 @@ export interface HotkeyCommand {* @default true*/shouldReturnFocusOnClose?: boolean;+ /**+ * If true, the keyDownHandler will NOT run in response to keyboard events+ * (letting the real handler, e.g. Lexical, process the key). The handler+ * WILL still run when the command is invoked from the command menu (where+ * there is no KeyboardEvent). This allows a hotkey to appear in the command+ * palette with its shortcut while another system owns the actual keystroke.+ */+ proxiedHotkey?: boolean;}export interface HotkeyRegistrationOptions {@@ -160,6 +168,15 @@ export interface HotkeyRegistrationOptions {* @default true*/shouldReturnFocusOnClose?: boolean;++ /**+ * If true, the keyDownHandler will NOT run in response to keyboard events+ * (letting the real handler, e.g. Lexical, process the key). The handler+ * WILL still run when the command is invoked from the command menu (where+ * there is no KeyboardEvent). This allows a hotkey to appear in the command+ * palette with its shortcut while another system owns the actual keystroke.+ */+ proxiedHotkey?: boolean;}export type HotkeyGroup = {diff --git a/js/app/packages/core/hotkey/utils.ts b/js/app/packages/core/hotkey/utils.tsindex 74eb580181..2f54fe74eb 100644--- a/js/app/packages/core/hotkey/utils.ts+++ b/js/app/packages/core/hotkey/utils.ts@@ -468,7 +468,11 @@ export function runCommand(}}- const captured = command.keyDownHandler?.(e);+ // For proxied hotkeys, skip the handler when triggered by a real keyboard+ // event (let the proxied system, e.g. Lexical, handle the keystroke).+ // The handler still runs when invoked from the command menu (e is undefined).+ const captured =+ e && command.proxiedHotkey ? false : command.keyDownHandler?.(e);stopPropagation = captured ?? stopPropagation;if (captured) {@@ -619,6 +623,7 @@ export function registerScopeSignalHotkey(hide: args.hide,icon: args.icon,tags: args.tags,+ proxiedHotkey: args.proxiedHotkey,});disposer = result.dispose;