Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(markdown-editor): share the .tiptap-content scroll-parent hook

Sergey Kozyrenko6c3a011fe26f
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-image-handle.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor-image-handle.tsx
index 731d9c04..60d0234d 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-image-handle.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-image-handle.tsx
@@ -7,6 +7,7 @@ import { useEffect, useState } from 'react';
import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover';
import { ImageEditForm } from './markdown-editor-image-edit-form';
+import { getEditorScrollParent } from './markdown-editor-styles';
interface ImageTarget {
alt: string;
@@ -97,7 +98,7 @@ function useImageHandle(editor: Editor) {
editor.on('selectionUpdate', update);
// Fixed-positioned anchor goes stale on scroll/resize — drop it (it reappears on the next selection).
- const scrollParent = editor.view.dom.closest('.tiptap-content') ?? window;
+ const scrollParent = getEditorScrollParent(editor.view.dom);
scrollParent.addEventListener('scroll', clear, { passive: true });
window.addEventListener('resize', clear);
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-link-handle.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor-link-handle.tsx
index 406e6a0f..e8216e05 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-link-handle.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-link-handle.tsx
@@ -6,6 +6,7 @@ import { useEffect, useState } from 'react';
import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover';
import { LinkEditForm } from './markdown-editor-link-edit-form';
+import { getEditorScrollParent } from './markdown-editor-styles';
interface LinkTarget {
href: string;
@@ -108,7 +109,7 @@ function useLinkHandle(editor: Editor) {
editor.on('selectionUpdate', update);
// Fixed-positioned anchor goes stale on scroll/resize — drop it (it reappears on the next caret entry).
- const scrollParent = editor.view.dom.closest('.tiptap-content') ?? window;
+ const scrollParent = getEditorScrollParent(editor.view.dom);
scrollParent.addEventListener('scroll', clear, { passive: true });
window.addEventListener('resize', clear);
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-styles.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-styles.ts
index 29a7d2ce..d3c3748b 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-styles.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-styles.ts
@@ -2,3 +2,12 @@
// lazy-load fallback can wear the same box as the mounted editor without pulling the tiptap chunk eagerly.
export const MARKDOWN_EDITOR_WRAPPER_CLASS =
'border-input dark:bg-input/30 group/markdown-editor flex w-full flex-col overflow-hidden rounded-md border shadow-2xs outline-hidden transition-[color,box-shadow] has-[[aria-invalid=true]]:border-destructive';
+
+// The editor's scrollable content wrapper. The link/image/table overlay handles find their dismiss-on-scroll
+// parent by THIS class — a behavioral hook, not just styling — so it must stay in sync with the className that
+// stamps it on the contenteditable (markdown-editor.tsx) and with getEditorScrollParent below.
+export const EDITOR_CONTENT_CLASS = 'tiptap-content';
+
+// The scroll parent an editor overlay anchors to; falls back to window when the editor isn't inside a scroll box.
+export const getEditorScrollParent = (editorDom: Element): Element | Window =>
+ editorDom.closest(`.${EDITOR_CONTENT_CLASS}`) ?? window;
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-table-handles.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor-table-handles.tsx
index 09cefa6f..15ddb2b5 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-table-handles.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-table-handles.tsx
@@ -28,6 +28,7 @@ import {
} from '@/components/ui/dropdown-menu';
import { Switch } from '@/components/ui/switch';
+import { getEditorScrollParent } from './markdown-editor-styles';
import { ALIGN_OPTIONS, clearLineContents, hasHeaderRow, setColumnAlign } from './markdown-editor-table-commands';
interface HoverTarget {
@@ -342,7 +343,7 @@ function useTableHandles(editor: Editor): TableHandlesController {
// table visually; a doc edit shifts every position after it, so a menu action would resolve the stale
// cellPos against the current doc (wrong row/column, or an out-of-bounds RangeError in the header
// selector). Drop the target in both cases — it reappears on the next hover.
- const scrollParent = dom.closest('.tiptap-content') ?? window;
+ const scrollParent = getEditorScrollParent(dom);
const dropStaleTarget = () => {
if (!openRef.current) {
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
index f85d8c46..9b2cdd37 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
@@ -12,7 +12,7 @@ import { cn } from '@/lib/utils';
import { createMarkdownExtensions } from './markdown-editor-extensions';
import { ImageHandle } from './markdown-editor-image-handle';
import { LinkHandle } from './markdown-editor-link-handle';
-import { MARKDOWN_EDITOR_WRAPPER_CLASS as WRAPPER_CLASS } from './markdown-editor-styles';
+import { EDITOR_CONTENT_CLASS, MARKDOWN_EDITOR_WRAPPER_CLASS as WRAPPER_CLASS } from './markdown-editor-styles';
import { TableHandles } from './markdown-editor-table-handles';
import { MarkdownEditorToolbar } from './markdown-editor-toolbar';
import { findVariableOccurrences } from './markdown-editor-variable-highlight';
@@ -139,7 +139,7 @@ function MarkdownEditor({
/>
<EditorContent
className={cn(
- 'prose prose-sm dark:prose-invert tiptap-content max-w-none min-w-0 flex-1 overflow-auto px-3 py-2',
+ `prose prose-sm dark:prose-invert ${EDITOR_CONTENT_CLASS} max-w-none min-w-0 flex-1 overflow-auto px-3 py-2`,
'[&_.ProseMirror]:min-h-full [&_.ProseMirror]:outline-none',
)}
editor={editor}