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): fix node accessory position for deeply nested node accessories (#1428)

Seamus0340a80acde7
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/accessory/CodeBoxAccessory.tsx b/js/app/packages/core/component/LexicalMarkdown/component/accessory/CodeBoxAccessory.tsx
index 73cc00874f..b98d66e22b 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/accessory/CodeBoxAccessory.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/accessory/CodeBoxAccessory.tsx
@@ -2,7 +2,6 @@
* @file This component rendered the accessory for the code nodes - a copy button and a syntax highlighting
* language selector.
*/
-
import { isInBlock, useIsNestedBlock } from '@core/block';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
import { DeprecatedTextButton } from '@core/component/DeprecatedTextButton';
@@ -33,8 +32,8 @@ import {
} from '@lexical-core';
import {
$getNodeByKey,
- type EditorThemeClasses,
type LexicalEditor,
+ type EditorThemeClasses,
type NodeKey,
} from 'lexical';
import {
@@ -222,9 +221,11 @@ export function CodeBoxAccessory(props: {
<Show when={!isNested}>
<div
class="fixed pointer-events-none md-code-box-header"
- use:glueToElement={{
- element: () => props.floatRef,
- editor: props.editor,
+ ref={(el) => {
+ glueToElement(el, () => ({
+ editor: props.editor,
+ element: () => props.floatRef,
+ }));
}}
>
<div class="w-full flex justify-between content-center items-center p-1 pointer-events-auto text-ink-extra-muted">
diff --git a/js/app/packages/core/component/LexicalMarkdown/directive/glueToElement.ts b/js/app/packages/core/component/LexicalMarkdown/directive/glueToElement.ts
index fdb040ef00..1ff94bf0af 100644
--- a/js/app/packages/core/component/LexicalMarkdown/directive/glueToElement.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/directive/glueToElement.ts
@@ -36,7 +36,9 @@ export function glueToElement(
async function updatePosition() {
const el = propAccessor().element();
- if (!el) {
+ const root = propAccessor().editor.getRootElement();
+
+ if (!el || !root) {
style(floatingElement, { display: 'none' });
return;
}
@@ -46,10 +48,13 @@ export function glueToElement(
});
const rect = el.getBoundingClientRect();
+ const rootRect = root.getBoundingClientRect();
+ const offsetLeft = rect.left - rootRect.left;
+ const offsetTop = rect.top - rootRect.top;
style(floatingElement, {
- left: `${el.offsetLeft}px`,
- top: `${el.offsetTop}px`,
+ left: `${offsetLeft}px`,
+ top: `${offsetTop}px`,
width: `${rect.width}px`,
height: `${rect.height}px`,
visibility: middlewareData.hide?.referenceHidden ? 'hidden' : 'visible',