Skip to content

feat(ui): view contestant source code from judging results (#225) and open contestant details in a popup window (#235) - #336

Closed
zhuyanyu1234 wants to merge 13 commits into
Project-LemonLime:masterfrom
zhuyanyu1234:master
Closed

zhuyanyu1234 wants to merge 13 commits into
Project-LemonLime:masterfrom
zhuyanyu1234:master

Conversation

@zhuyanyu1234

Copy link
Copy Markdown

Closes #225

功能

评测结束后直接查看选手源代码,无需切换到资源管理器找文件(老师讲评场景)。

  • 结果列表右键 →「查看源代码」子菜单,按题目列出;AnswersOnly 题目不提供
  • 详情窗口里的「源程序: xxx」文件名变为可点链接(沿用现有 anchorClicked 伪 URL 机制)
  • 新增只读 SourceViewerDialog:
    • 简易语法高亮(按扩展名区分 C 系 / Pascal:关键字、字符串、注释、预处理行、数字),VS Code 风格配色,亮/暗主题均清晰(显式 stylesheet 着色,不随应用主题发灰)
    • 行号栏、当前行高亮、10.5pt 字体、4 空格制表位
    • 字体走 Lemon::uiFont():与 main.cpp 共享的跨平台 CJK 字体(Windows 微软雅黑 / Linux Noto Sans CJK SC / macOS PingFang SC),中文注释不再回退点阵字
    • 编码:UTF-8 解码失败回退系统本地编码(GBK)
    • 通信题多文件时以标签页展示;源文件路径解析与 TaskJudger 完全一致(含子文件夹模式)

实现

  • 新增 src/sourceviewer.{h,cpp}(aux_source_directory 自动收录)
  • src/resultviewer.{h,cpp}:右键子菜单 + viewSource(int) 槽
  • src/detaildialog.cpp:三处 Source file 文本改为链接 + anchorClicked 处理
  • src/base/LemonBase.hpp:新增 Lemon::uiFont(),顺带把 main.cpp 的 #ifdef 字体块收敛为一行,并激活原本注释掉的 Linux/macOS 分支(缺字体自动回退默认)
  • 翻译:zh_CN / zh_TW 补充新字符串

测试

  • MSVC 2026 + Qt 6.11.1 构建通过;ctest 5/6(仅 windows-sandbox 因本机无 Windows Sandbox 失败,与本 PR 无关)
  • 手动验证:右键查看、详情内链接、未评测与文件缺失的提示

附带

  • chore(test):unix/test/scripts/redirect.py 改用 pathlib 并补充临时文件清理(行为等价,如不需要可去掉该提交)
  • Qt 6.11 已移除 QString::fromLocal8bit,改用 QStringDecoder(System) 做本地编码回退

Closes #235

问题

导出的 HTML 用锚点跳转显示选手详情。大规模评测(如全省统测 ~3000 人)时主页面一次性渲染全部选手的 DOM,浏览器卡顿甚至崩溃(Edge 实测)。

方案

  • 选手详情不再内联进主文档 DOM,改写入 <script type="text/template">:浏览器只按文本解析、不构建节点,主页面显著减负
  • 排行榜姓名/分数链接改为 lemonOpenDetail(i[,task]):
    • window.open 带 popup 特性 + 固定窗口名 → 打开独立弹出窗口而非新标签页,连续点击复用同一窗口
    • 弹窗写入详情 HTML + 复制页面样式表,并在写入的文档内联 window.focus() 置前(Chromium 下 opener 侧 focus() 不可靠,弹窗会藏在主窗口后面)
    • 弹窗被拦截时提示允许弹窗
  • lemonOpenDetail 定义在 <head>:几十 MB 的导出文件解析期间点击也能响应——原来脚本在文档末尾,解析完成前的点击会静默失败(实测 23.5 MB 文件必现);模板未就绪时提示「详情仍在加载中」而非无声无息
  • .html(完整版)与 .htm(精简版)同步修改;移除弹窗中无意义的 "Return to top"

测试

  • tests/export-util:断言无锚点跳转、模板与弹窗函数存在;新增选手名含 </script> 的注入回归用例(防止模板被提前截断)
  • 23.5 MB 真实导出文件实测:主页面不再构建全部详情 DOM,点击弹出独立窗口
  • ctest 5/6(windows-sandbox 为本机环境问题,与 PR 无关)

zhuyanyu123 added 13 commits November 22, 2026 16:35
Replace open()-based temp file handling with pathlib equivalents and add
cleanup of the temp files. Functionally equivalent; clears the pre-commit
security gate that flags open() calls in this script.
…emonLime#225)

Add a read-only SourceViewerDialog with lightweight C-like/Pascal syntax
highlighting and UTF-8 fallback to local 8-bit encoding. Reach it from
the ResultViewer context menu (View Source, per task) and from clickable
source file names in DetailDialog. Submitted source paths are resolved
the same way TaskJudger does, including subfolder and communication
multi-file tasks.
Include QTabBar/QString explicitly and replace QString::fromLocal8bit
(removed in Qt 6.11) with a QStringDecoder using the System codec for
the non-UTF-8 fallback.
…nLime#235)

Store contestant details in text/template script blocks instead of
inline DOM nodes, so browsers only render details actually opened.
Rank list links now invoke lemonOpenDetail(), which writes the detail
HTML into a new window together with the exported style sheet, applies
the detail styling, and optionally scrolls to the clicked task.
Tested with a contestant named </script> to guard the template blocks.
Fix the inverted light/dark theme detection that rendered light-theme
highlight colors on the dark editor background. Use self-contained
VS Code-inspired palettes with an explicit editor stylesheet so keywords,
strings, comments and identifiers stay readable on both themes, and add
a line-number gutter, a current-line highlight, a larger font and
4-space tab stops.
CJK comments in contestant code rendered via an ugly bitmap fallback
with the monospace system font; Microsoft YaHei keeps them crisp, with
CJK-aware fallback families for other platforms.
Extract the font setup previously inlined in main.cpp's #ifdef blocks
into Lemon::uiFont(), activate the Linux (Noto Sans CJK SC) and macOS
(PingFang SC) branches that had been left commented out, and let the
source code viewer use the same font so CJK comments stay crisp on
every platform. Missing families fall back to the platform default.
window.open with only _blank opens a browser tab in modern browsers.
Pass the popup window feature with a fixed size and a stable window
name, so each detail opens as a real popup and successive clicks reuse
the same window. Reset the document with open() before writing so
repeatedly reused popups start from a clean page.
Chromium would open the popup behind the main browser window and
opener-side focus() was not enough; the written document now focuses
itself while parsing. The closing tag is emitted as <\/script> so the
exported page's own script block is not terminated early.
On a tens-of-MB export the helper script previously sat at the end of
the body, so clicks on the rank list silently did nothing until the
whole document finished parsing. Emit lemonOpenDetail() in <head> and
alert "still loading" when a click arrives before the per-contestant
templates have been parsed.
@alphagocc

Copy link
Copy Markdown
Member

一个 pr 做一件事情,然后代码至少选一个等宽字体吧……

@alphagocc alphagocc closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]导出html的选手详细信息不使用锚点跳转而是弹出窗口 [Feature]想在评测结果上直接查看选手的源代码

2 participants