Skip to content

Commit 556d891

Browse files
xiaoboxclaude
andcommitted
fix(table-block): 修复表格工具栏滚动时不消失的问题
- 改进滚动容器检测逻辑,遍历所有父元素查找可滚动容器 - 确保监听 .wysiwyg-rendered 和 .preview-container 的滚动事件 - 修复 destroy() 中未清理滚动事件监听器导致的内存泄漏 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c2b72b8 commit 556d891

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

src/plugins/table-block/index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,30 @@ export const tableBlockPlugin = $prose((ctx) => {
849849
hideAllHandles()
850850
}
851851
// Listen to scroll on the editor container and window
852-
const scrollContainer = editorView.dom.closest('.wysiwyg-rendered') || editorView.dom.parentElement
853-
if (scrollContainer) {
854-
scrollContainer.addEventListener('scroll', handleScroll)
852+
// Find all scrollable ancestors to ensure we catch scroll events
853+
const scrollContainers = []
854+
let el = editorView.dom
855+
while (el && el !== document.body) {
856+
const style = window.getComputedStyle(el)
857+
const overflow = style.overflow + style.overflowY + style.overflowX
858+
if (overflow.includes('scroll') || overflow.includes('auto')) {
859+
scrollContainers.push(el)
860+
}
861+
el = el.parentElement
862+
}
863+
// Also check the immediate parent and ancestors with specific classes
864+
const wysiwygRendered = editorView.dom.closest('.wysiwyg-rendered')
865+
if (wysiwygRendered && !scrollContainers.includes(wysiwygRendered)) {
866+
scrollContainers.push(wysiwygRendered)
867+
}
868+
const previewContainer = editorView.dom.closest('.preview-container')
869+
if (previewContainer && !scrollContainers.includes(previewContainer)) {
870+
scrollContainers.push(previewContainer)
855871
}
872+
// Bind scroll listeners to all found containers
873+
scrollContainers.forEach((container) => {
874+
container.addEventListener('scroll', handleScroll)
875+
})
856876
window.addEventListener('scroll', handleScroll, true)
857877

858878
return {
@@ -865,11 +885,17 @@ export const tableBlockPlugin = $prose((ctx) => {
865885
window.removeEventListener('dragover', handleDragOver)
866886
window.removeEventListener('dragend', handleDragEnd)
867887
window.removeEventListener('drop', handleDrop)
888+
window.removeEventListener('scroll', handleScroll, true)
868889

869890
editorView.dom.removeEventListener('pointermove', handlePointerMove)
870891
editorView.dom.removeEventListener('pointerleave', handlePointerLeave)
871892
editorView.dom.removeEventListener('click', handleEditorClick)
872893

894+
// Clean up scroll listeners on all containers
895+
scrollContainers.forEach((container) => {
896+
container.removeEventListener('scroll', handleScroll)
897+
})
898+
873899
if (dom.wrapper.parentElement) {
874900
dom.wrapper.parentElement.removeChild(dom.wrapper)
875901
}

0 commit comments

Comments
 (0)