-
Notifications
You must be signed in to change notification settings - Fork 180
fix(XMarkdown): 修复代码块控制按钮显示逻辑 #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "fix/418-\u9884\u89C8\u6309\u94AE\u5C55\u793A\u903B\u8F91\u95EE\u9898"
Conversation
重构控制按钮渲染函数,统一 controlEle 和 controlHasRunCodeEle 的逻辑, 修复 needViewCodeBtn 导致主题切换按钮异常隐藏的问题。 Closes element-plus-x#418
📝 WalkthroughWalkthroughThis PR restores HTML code block preview button functionality by refactoring the control element composition. It modifies the CodeBlock component to pass an optional view callback to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/components/XMarkdownCore/components/CodeBlock/shiki-header.ts (1)
222-242: Critical: MissingtoValueimport.Line 224 uses
toValuebut it's not imported. This will cause a runtime error when the function executes.🐛 Proposed fix
Add
toValueto the imports fromvue:-import { h, ref } from 'vue'; +import { h, ref, toValue } from 'vue';
🧹 Nitpick comments (2)
packages/core/src/components/XMarkdownCore/components/CodeBlock/shiki-header.ts (2)
223-226: LGTM: Unified preview button logic.The consolidated logic correctly determines when to show the preview button by checking both
needViewCodeBtnandenableCodePreview. This fixes the issue where the theme toggle button was incorrectly hidden.Note: This logic is similar to
nowViewBtnShowcomputed inindex.vue(lines 46-51). Consider extracting this into a shared utility if it needs to be reused elsewhere to maintain consistency.
248-254: Consider adding version and removal timeline information to the deprecation notice.The deprecation is properly implemented with correct delegation to
controlEle. However, unlike most deprecations in the codebase, it lacks version context. For consistency and to help external consumers, consider enhancing the JSDoc:* @deprecated 已废弃,请使用 controlEle 代替 (since v1.x.x, will be removed in v2.0.0)Note: The function is not used internally, so it only affects external consumers.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/core/src/components/XMarkdownCore/components/CodeBlock/index.vuepackages/core/src/components/XMarkdownCore/components/CodeBlock/shiki-header.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/components/XMarkdownCore/components/CodeBlock/index.vue (3)
packages/core/src/components/XMarkdownCore/components/RunCode/type.d.ts (4)
ElxRunCodeContentProps(85-90)ElxRunCodeExposeProps(92-101)ElxRunCodeContentExposeProps(103-112)ElxRunCodeProps(28-73)packages/core/src/components/XMarkdownCore/shared/constants.ts (1)
enableCodePreview(66-71)packages/core/src/components/XMarkdownCore/shared/types.d.ts (1)
CodeXProps(37-42)
🔇 Additional comments (2)
packages/core/src/components/XMarkdownCore/components/CodeBlock/index.vue (2)
45-51: LGTM: Correctly implements dual-flag check.The
nowViewBtnShowcomputed property correctly enables HTML code block special handling when eitherneedViewCodeBtnorenableCodePreviewis true, addressing the issue described in #418.
183-189: LGTM: Clean refactoring to unified controlEle.The refactored logic correctly creates a
viewCallbackonly for HTML code blocks when view functionality is enabled, then passes it to the unifiedcontrolElefunction. This simplifies the previous conditional path that selected betweencontrolEleandcontrolHasRunCodeEle.
重构控制按钮渲染函数,统一 controlEle 和 controlHasRunCodeEle 的逻辑, 修复 needViewCodeBtn 导致主题切换按钮异常隐藏的问题。
Closes #418
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.