Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(page-editor): hide line comment marker over overflowing tables (#21541)

Rdmclin27513e199d1bd
diff --git a/src/features/PageEditor/DocumentComments/BlockCommentMarker.test.ts b/src/features/PageEditor/DocumentComments/BlockCommentMarker.test.ts
index 32b87dcb0ae..bd5a6f4466f 100644
--- a/src/features/PageEditor/DocumentComments/BlockCommentMarker.test.ts
+++ b/src/features/PageEditor/DocumentComments/BlockCommentMarker.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { blockAt, inMarkerBridge, lineAt } from './BlockCommentMarker';
+import { blockAt, inMarkerBridge, lineAt, scrollsUnderMarker } from './BlockCommentMarker';
const rect = (partial: Partial<DOMRect>): DOMRect =>
({ bottom: 0, left: 0, right: 0, top: 0, ...partial }) as DOMRect;
@@ -103,3 +103,29 @@ describe('blockAt', () => {
expect(blockAt(body, null)).toBeNull();
});
});
+
+describe('scrollsUnderMarker', () => {
+ /** A table block as the editor renders it: block > scroll wrapper > table. */
+ const mountTable = (scrollWidth: number, clientWidth: number) => {
+ const block = document.createElement('div');
+ const wrapper = document.createElement('div');
+ wrapper.className = 'lobe-editor-table-scroll-wrapper';
+ wrapper.append(document.createElement('table'));
+ block.append(wrapper);
+ Object.defineProperty(wrapper, 'scrollWidth', { value: scrollWidth });
+ Object.defineProperty(wrapper, 'clientWidth', { value: clientWidth });
+ return block;
+ };
+
+ it('flags a table wider than the column, which scrolls under the marker', () => {
+ expect(scrollsUnderMarker(mountTable(900, 600))).toBe(true);
+ });
+
+ it('keeps the marker for a table that fits the column', () => {
+ expect(scrollsUnderMarker(mountTable(600, 600))).toBe(false);
+ });
+
+ it('keeps the marker for a block without a table', () => {
+ expect(scrollsUnderMarker(document.createElement('p'))).toBe(false);
+ });
+});
diff --git a/src/features/PageEditor/DocumentComments/BlockCommentMarker.tsx b/src/features/PageEditor/DocumentComments/BlockCommentMarker.tsx
index 99fc88e7981..08c5915f359 100644
--- a/src/features/PageEditor/DocumentComments/BlockCommentMarker.tsx
+++ b/src/features/PageEditor/DocumentComments/BlockCommentMarker.tsx
@@ -95,6 +95,25 @@ export const blockAt = (body: HTMLElement, target: EventTarget | null): HTMLElem
return node instanceof HTMLElement ? node : null;
};
+/**
+ * The editor's table scroll wrapper bleeds into the column's anchor padding on
+ * both sides (`margin-inline: -padding`), so a table wider than the column
+ * scrolls through the very margin the marker sits in.
+ */
+const TABLE_SCROLL_WRAPPER_SELECTOR = '.lobe-editor-table-scroll-wrapper';
+
+/**
+ * Whether `block` holds a table that overflows horizontally β€” its content then
+ * runs under the marker, which would float over the cells. Such a block gets
+ * no marker; its text can still be commented on through a selection.
+ */
+export const scrollsUnderMarker = (block: HTMLElement): boolean => {
+ const wrappers = block.matches(TABLE_SCROLL_WRAPPER_SELECTOR)
+ ? [block]
+ : Array.from(block.querySelectorAll<HTMLElement>(TABLE_SCROLL_WRAPPER_SELECTOR));
+ return wrappers.some((wrapper) => wrapper.scrollWidth > wrapper.clientWidth);
+};
+
/**
* Whether a point sits in the corridor bridging the body and the marker, at
* the marker's own row height β€” the natural path from a highlighted line to
@@ -170,8 +189,9 @@ const BlockCommentMarker = memo<{ hostRef: React.RefObject<HTMLElement | null> }
return;
}
// A line with nothing to quote (an empty paragraph, a divider) has no
- // marker: the anchor it would produce is empty.
- const range = lineAt(block, event.clientY);
+ // marker: the anchor it would produce is empty. Nor does a table that
+ // scrolls under the marker's margin.
+ const range = scrollsUnderMarker(block) ? null : lineAt(block, event.clientY);
if (!range) {
setTarget(null);
return;