Skip to content

feat(app): add preview and source view options for markdown files in file tabs - #13704

Closed
kimi-chen wants to merge 4 commits into
anomalyco:devfrom
kimi-chen:dev
Closed

feat(app): add preview and source view options for markdown files in file tabs#13704
kimi-chen wants to merge 4 commits into
anomalyco:devfrom
kimi-chen:dev

Conversation

@kimi-chen

@kimi-chenkimi-chen commented Feb 15, 2026

Copy link
Copy Markdown

Description

This PR closes#13705 by adding a preview/source toggle for Markdown files in the file viewer, allowing users to switch between rendered markdown preview and raw source code.

What's Changed

UI Enhancement:

  • Added a toggle button group (Preview/Source) that appears at the top of Markdown files
  • Preview mode is enabled by default when opening .md or .markdown files
  • Users can switch between:
    • Preview mode (eye icon): Renders the markdown content
    • Source mode (code icon): Shows the raw markdown code

Implementation Details:

  • Added isMarkdown() memo to detect Markdown files by extension
  • Introduced previewMode signal to track the current view state
  • Integrated IconButton and Markdown components from the UI library
  • Preview uses the existing Markdown component with proper caching

Internationalization:
Added translations for the new UI elements in all supported language

Files Modified

  • packages/app/src/pages/session/file-tabs.tsx - Main implementation
  • packages/app/src/i18n/*.ts - Translation strings for all languages
image

CopilotAI review requested due to automatic review settings February 15, 2026 08:47
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Preview/Source toggle specifically for Markdown files in the session file tabs, enabling users to switch between rendered Markdown and the raw file contents.

Changes:

  • Detect Markdown files by extension and track a per-tab previewMode state (defaulting to Preview for Markdown).
  • Render a sticky toggle header (Preview/Source) for Markdown files and display the Markdown component in Preview mode.
  • Add new i18n strings for the toggle labels in several locales.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
packages/app/src/pages/session/file-tabs.tsxAdds Markdown detection, preview state, toggle UI, and Markdown rendering path.
packages/app/src/i18n/en.tsAdds English strings for “Preview” / “Source”.
packages/app/src/i18n/de.tsAdds German strings for “Preview” / “Source”.
packages/app/src/i18n/fr.tsAdds French strings for “Preview” / “Source”.
packages/app/src/i18n/es.tsAdds Spanish strings for “Preview” / “Source”.
packages/app/src/i18n/ja.tsAdds Japanese strings for “Preview” / “Source”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadpackages/app/src/pages/session/file-tabs.tsx Outdated
Comment on lines +552 to +555
<Match when={state()?.loaded && isMarkdown() && previewMode()}>
<div class="px-6 py-4 pb-40">
<Markdown text={contents()} cacheKey={cacheKey()} />
</div>

CopilotAIFeb 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When previewMode() is true, the code viewer (renderCode) is not mounted, which also removes line selection + inline comment rendering. As a result, if props.comments.focus() targets a markdown file (e.g. navigating to an existing comment), the focused comment won’t be visible until the user manually switches to Source. Consider auto-switching to Source when a focused comment is for the current file (or when there are existing comments for the file) to preserve the existing focus/navigation behavior.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Also, would like to see this feature merged. I looked into this and put together a fix. In the createEffect that handles props.comments.focus() (around line 244), adding these 5 lines before the requestAnimationFrame call resolves it:


// Auto-switch to Source view if in Preview mode for markdown files
// so that the focused comment is visible (comments are only rendered in source view)
if (isMarkdown() && previewMode()) {
setPreviewMode(false)
}

So the full effect becomes:


createEffect(() => {
const focus = props.comments.focus()
const p = path()
if (!focus || !p) return
if (focus.file !== p) return
if (props.activeTab() !== props.tab) return
const target = fileComments().find((comment) => comment.id === focus.id)
if (!target) return
setNote("openedComment", target.id)
setNote("commenting", null)
props.file.setSelectedLines(p, target.selection)
// Auto-switch to Source view if in Preview mode for markdown files
// so that the focused comment is visible (comments are only rendered in source view)
if (isMarkdown() && previewMode()) {
setPreviewMode(false)
}
requestAnimationFrame(() => props.comments.clearFocus())
})

Comment threadpackages/app/src/i18n/en.ts
kimi-chenand others added 2 commits February 15, 2026 20:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alankyshum

Copy link
Copy Markdown

Hey @kimi-chen — are you still working on this? I'd love to see this feature land. The PR currently has merge conflicts with dev and the unit/test CI checks are failing.

Happy to help rebase and fix the tests if you'd like, or I can open a fresh PR based on your work (with credit, of course). Just let me know!

alankyshum added a commit to alankyshum/opencode that referenced this pull request Apr 11, 2026
Add a Preview/Source toggle for Markdown files in the session file viewer.
Detects .md/.markdown files and defaults to rendered preview mode.
Auto-switches to Source view when navigating to a comment.
Excludes binary files from the toggle.
Includes i18n translations for all 17 supported locales.
Based on work by @kimi-chen in anomalyco#13704.
Co-authored-by: kimi-chen <kimi-chen@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
alankyshum added a commit to alankyshum/opencode that referenced this pull request Apr 11, 2026
Add a Preview/Source toggle for Markdown files in the session file viewer.
Detects .md/.markdown files and defaults to rendered preview mode.
Auto-switches to Source view when navigating to a comment.
Excludes binary files from the toggle.
Includes i18n translations for all 17 supported locales.
Based on work by @kimi-chen in anomalyco#13704.
Co-authored-by: kimi-chen <kimi-chen@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
alankyshum added a commit to alankyshum/opencode that referenced this pull request Apr 11, 2026
Add a Preview/Source toggle for Markdown files in the session file viewer.
Detects .md/.markdown files and defaults to rendered preview mode.
Auto-switches to Source view when navigating to a comment.
Excludes binary files from the toggle.
Includes i18n translations for all 17 supported locales.
Based on work by @kimi-chen in anomalyco#13704.
Co-authored-by: kimi-chen <kimi-chen@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
alankyshum added a commit to alankyshum/opencode that referenced this pull request Apr 13, 2026
Add a Preview/Source toggle for Markdown files in the session file viewer.
Detects .md/.markdown files and defaults to rendered preview mode.
Auto-switches to Source view when navigating to a comment.
Excludes binary files from the toggle.
Includes i18n translations for all 17 supported locales.
Based on work by @kimi-chen in anomalyco#13704.
Co-authored-by: kimi-chen <kimi-chen@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
alankyshum added a commit to alankyshum/opencode that referenced this pull request Apr 17, 2026
Add a Preview/Source toggle for Markdown files in the session file viewer.
Detects .md/.markdown files and defaults to rendered preview mode.
Auto-switches to Source view when navigating to a comment.
Excludes binary files from the toggle.
Includes i18n translations for all 17 supported locales.
Based on work by @kimi-chen in anomalyco#13704.
Co-authored-by: kimi-chen <kimi-chen@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
Sign up for freeto 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]: Markdown Preview/Source Toggle in File Editor

4 participants

@kimi-chen@alankyshum@maxthman36