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): remove regex single line md in favor of lexical mutation, turn off launcher pc noise grid for now (#640)

Seamus2813da977b95
diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsx
index 6beddbf39f..424ca0126a 100644
--- a/js/app/packages/app/component/Launcher.tsx
+++ b/js/app/packages/app/component/Launcher.tsx
@@ -310,7 +310,9 @@ const LauncherMenuItem = (props: LauncherMenuItemProps) => {
buttonRef?.focus();
}}
>
- <div
+ {/** TODO (seamus): we need to pool/cache these canvases. they brick the color picker/or any other gl context
+ because they do not get garbage collected fast enough */}
+ {/*<div
class="inset-0 absolute bg-panel opacity-2 mask-b-from-0% mask-b-to-100%"
classList={{
'text-ink-extra-muted opacity-2': !props.focused,
@@ -328,7 +330,7 @@ const LauncherMenuItem = (props: LauncherMenuItemProps) => {
stroke={0}
speed={[props.focused ? 0.3 : 0, 0]}
/>
- </div>
+ </div>*/}
<div
class="absolute size-full inset-0 transition-transform origin-top opacity-20 ease duration-200 mix-blend-color"
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
index be1347bca0..0a8c5e5468 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
@@ -55,7 +55,7 @@ import { ENABLE_SVG_PREVIEW } from '@core/constant/featureFlags';
import type { MarkNode } from '@lexical/mark';
import type { SearchMatchNode } from '@lexical-core/nodes/SearchMatchNode';
import { theme as baseTheme, createTheme } from '../../theme';
-import { setEditorStateFromMarkdown } from '../../utils';
+import { forceSingleLine, setEditorStateFromMarkdown } from '../../utils';
import { StaticCodeBoxAccessory } from '../accessory/CodeBoxAccessory';
import { ContactMention as ContactMentionDecorator } from '../decorator/ContactMention';
import { DateMention as DateMentionDecorator } from '../decorator/DateMention';
@@ -146,42 +146,6 @@ const CodeHighlightShim = {
},
};
-/**
- * Take the first "line" of a markdown string. Handle the codeblock edge case.
- */
-export function firstLineMarkdown(md: string) {
- if (typeof md !== 'string') return '';
-
- // fix line endings and trim start
- md = md.replace(/\r\n?/g, '\n').replace(/^\s*\n/, '');
-
- const lines = md.split('\n');
- const collapse = (s: string) => s.replace(/\s+/g, ' ').trim();
-
- const fenceMatch = lines[0]?.match(/^\s*(```+|~~~+)\s*([a-zA-Z0-9_-]+)?\s*$/);
- if (fenceMatch) {
- const fence = fenceMatch[1]; // ``` or ~~~ (with count)
- const lang = fenceMatch[2] || ''; // optional
- let firstCode = '';
- for (let i = 1; i < lines.length; i++) {
- // closing fence?
- if (new RegExp(`^\\s*${fence}\\s*$`).test(lines[i])) break;
- if (!firstCode && lines[i].trim().length)
- firstCode = lines[i].replace(/\s+$/, '');
- }
- const out =
- (lang ? '```' + lang : '```') + '\n' + (firstCode || '') + '\n```';
- return out;
- }
-
- const buf = [];
- for (let i = 0; i < lines.length; i++) {
- if (/^\s*$/.test(lines[i])) break;
- buf.push(lines[i]);
- }
- return collapse(buf.join(' '));
-}
-
function newStaticRenderingEditor(props: {
parentEditor?: LexicalEditor;
theme: EditorThemeClasses;
@@ -683,6 +647,7 @@ function Document(props: {
theme: EditorThemeClasses;
rootRef?: (ref: HTMLDivElement) => void;
isGenerating: Accessor<boolean>;
+ singleLine?: boolean;
}): JSX.Element {
return (
<div
@@ -740,9 +705,6 @@ export function StaticMarkdown(props: {
});
const content = createMemo(() => {
- if (props.singleLine) {
- return firstLineMarkdown(props.markdown);
- }
return props.markdown;
});
@@ -754,6 +716,9 @@ export function StaticMarkdown(props: {
}
setEditorStateFromMarkdown(editor, content(), props.target);
+ if (props.singleLine) {
+ forceSingleLine(editor);
+ }
setEditorState(editor.getEditorState());
});
@@ -766,6 +731,9 @@ export function StaticMarkdown(props: {
// Handle citations without affecting mentions
replaceCitations(content()).then((content: string) => {
setEditorStateFromMarkdown(editor, content, props.target);
+ if (props.singleLine) {
+ forceSingleLine(editor);
+ }
setEditorState(editor.getEditorState());
});
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/utils.ts b/js/app/packages/core/component/LexicalMarkdown/utils.ts
index f75d0c9926..e630647501 100644
--- a/js/app/packages/core/component/LexicalMarkdown/utils.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/utils.ts
@@ -1176,3 +1176,80 @@ export const $isAtEndOfTextNode = (selection: RangeSelection) => {
}
return false;
};
+
+const $singleLineNode = (node: ElementNode): ElementNode | null => {
+ if ($isParagraphNode(node)) {
+ const text = node.getTextContent().trim();
+ if (text === '') return null;
+
+ node.clear();
+ node.append($createTextNode(text.replace(/\s+/g, ' ')));
+ return node;
+ }
+
+ // text first text-ful list item and flatten to parent list
+ if ($isListNode(node)) {
+ const items = node.getChildren();
+
+ for (const item of items) {
+ if (!$isListItemNode(item)) continue;
+
+ const text = item.getTextContent().trim();
+ if (!text) continue;
+
+ item.clear();
+ item.append($createTextNode(text));
+
+ node.clear();
+ node.append(item);
+
+ return node;
+ }
+
+ return null;
+ }
+
+ // take first line with text
+ if ($isCodeNode(node)) {
+ const text = node.getTextContent().trim().split('\n')[0];
+ if (!text) return null;
+ node.clear();
+ node.append($createTextNode(text));
+ return node;
+ }
+
+ const text = node.getTextContent().trim();
+ if (!text) return null;
+
+ const p = $createParagraphNode();
+ p.append($createTextNode(text));
+ return p;
+};
+
+export function forceSingleLine(editor: LexicalEditor) {
+ editor.update(
+ () => {
+ const root = $getRoot();
+ const rootChildren = root.getChildren();
+
+ let firstChild: ElementNode | null = null;
+
+ for (const child of rootChildren) {
+ if (!$isElementNode(child)) continue;
+ const normalized = $singleLineNode(child);
+ if (normalized) {
+ firstChild = normalized;
+ break;
+ }
+ }
+
+ root.clear();
+ if (firstChild) {
+ root.append(firstChild);
+ } else {
+ root.append($createParagraphNode().append($createTextNode('')));
+ }
+ },
+ { discrete: true, tag: 'force-single-line' }
+ );
+}