fix: preserve table controls and editable Word list and code styles

This commit is contained in:
2026-11-04 16:20:07 +08:00
parent 3bb2cc5438
commit 6cc833183d
8 changed files with 231 additions and 8 deletions
+47
View File
@@ -0,0 +1,47 @@
"""Native pointer regression: reach and click the floating table copy button."""
import os,sys,time,json,tempfile
from pathlib import Path
os.environ.pop('QT_QPA_PLATFORM',None)
os.environ['QTWEBENGINE_CHROMIUM_FLAGS']='--log-level=3'
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from PySide6.QtWidgets import QApplication
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QPoint,Qt
from PySide6.QtTest import QTest
from PySide6.QtGui import QCursor
from mdhelper.markdown_renderer import MarkdownRenderer
app=QApplication([])
view=QWebEngineView();view.resize(850,450)
view.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint,True)
loaded=[];view.loadFinished.connect(loaded.append)
def wait(condition):
end=time.monotonic()+20
while not condition() and time.monotonic()<end:app.processEvents();time.sleep(.01)
assert condition()
def js(expression):
values=[];view.page().runJavaScript('JSON.stringify('+expression+')',values.append)
wait(lambda:values);return json.loads(values[0])
try:
root=Path(tempfile.gettempdir())
view.setHtml(MarkdownRenderer(root).render_source('| A | B |\n|---|---|\n| X | Y |',root/'hover.md'))
view.show();view.raise_();view.activateWindow()
wait(lambda:loaded and loaded[-1]);QTest.qWait(500)
bounds=js("(()=>{const t=document.querySelector('table').getBoundingClientRect(),b=document.querySelector('button').getBoundingClientRect();return {top:t.top,bottom:b.bottom,by:(b.top+b.bottom)/2,x:(b.left+b.right)/2}})()")
target=view.windowHandle()
js("(()=>{window.moves=[];document.addEventListener('mousemove',e=>window.moves.push([e.clientX,e.clientY,e.target.tagName]));return true})()")
QCursor.setPos(target.mapToGlobal(QPoint(20,20)));QTest.qWait(150)
for y in (bounds['top']+10,bounds['top']+1,(bounds['top']+bounds['bottom'])/2,bounds['by']):
point=QPoint(round(bounds['x']),round(y))
QCursor.setPos(target.mapToGlobal(point));QTest.mouseMove(target,point);QTest.qWait(400)
assert js("getComputedStyle(document.querySelector('.table-tools')).opacity")=='1', (y, js("({moves:window.moves,hover:[...document.querySelectorAll(':hover')].map(e=>e.className),width:innerWidth,height:innerHeight})"), app.platformName(), target.size(), view.size())
js("(()=>{window.copied=null;Object.defineProperty(navigator,'clipboard',{value:{writeText:async text=>{window.copied=text}}});return true})()")
QTest.mouseClick(target,Qt.MouseButton.LeftButton,pos=QPoint(round(bounds['x']),round(bounds['by'])))
QTest.qWait(200)
assert js('window.copied')=='A\tB\nX\tY'
print('Native hover and copy passed: continuous pointer path and expected table text.')
finally:
view.close()