Skip to content

feat: add word wrap toggle to code viewer#2207

Closed
thealxlabs wants to merge 4 commits intonpmx-dev:mainfrom
thealxlabs:feat/word-wrap-toggle
Closed

feat: add word wrap toggle to code viewer#2207
thealxlabs wants to merge 4 commits intonpmx-dev:mainfrom
thealxlabs:feat/word-wrap-toggle

Conversation

@thealxlabs
Copy link

🔗 Linked issue

resolves #2027

🧭 Context

The code viewer displayed long lines without any wrapping option, forcing horizontal scrolling. Users viewing files with very long lines (generated code, minified files, etc.) had no way to toggle word wrap.

📚 Description

  • Added a wordWrap boolean prop to Code/Viewer.vue that toggles a word-wrap CSS class on the code-lines container, enabling white-space: pre-wrap and overflow-wrap: break-word for long lines.
  • Added a word wrap toggle button to the file viewer page (package-code/.../[...filePath].vue) in the toolbar, using an aria-pressed attribute to reflect the active state.
  • Added the code.toggle_word_wrap i18n key.

A regression test (test/nuxt/components/CodeViewer.spec.ts) verifies that the word-wrap class is applied when wordWrap is true and absent when false.

@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 22, 2026 7:29pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 22, 2026 7:29pm
npmx-lunaria Ignored Ignored Mar 22, 2026 7:29pm

Request Review

@github-actions
Copy link

github-actions bot commented Mar 22, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
i18n/locales/en.json Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e03d24b-db5d-4e2a-9a65-4f92354122ef

📥 Commits

Reviewing files that changed from the base of the PR and between 040d8be and 5372860.

📒 Files selected for processing (2)
  • i18n/locales/en.json
  • i18n/schema.json
✅ Files skipped from review due to trivial changes (2)
  • i18n/locales/en.json
  • i18n/schema.json

📝 Walkthrough

Walkthrough

This PR adds word-wrap support to the code viewer. The CodeViewer component gains an optional wordWrap prop and corresponding scoped CSS to switch lines from pre to pre-wrap with overflow-wrap: break-word. The package file viewer page adds a reactive wordWrap flag, a toolbar toggle button that updates and passes the state into <CodeViewer>, and an i18n key for the toggle label. Tests were added to verify the component renders the word-wrap class when the prop is enabled.

Suggested reviewers

  • danielroe
  • ghostdevv
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description directly relates to the changeset, explaining the addition of word wrap functionality to the code viewer component.
Linked Issues check ✅ Passed All requirements from issue #2027 are met: word wrap toggle functionality added to the code viewer, UI control implemented in the toolbar, and translations provided.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing word wrap functionality as specified in issue #2027; no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
i18n/locales/en.json (1)

1-2: ⚠️ Potential issue | 🟡 Minor

Regenerate the i18n schema file.

The i18n/schema.json file is stale and missing newly added keys (toggle_word_wrap, dependents, and others). Run pnpm run generate:i18n-schema to regenerate it from i18n/locales/en.json.

🧹 Nitpick comments (3)
app/components/Code/Viewer.vue (1)

167-180: Remove duplicative/dead CSS selectors.

Lines 167-173 define styles for .code-content.word-wrap-active and .code-content:has(.word-wrap), whilst lines 175-180 target .code-lines.word-wrap. Based on the template at line 125, only the .code-lines element receives the word-wrap class, so:

  • .code-content.word-wrap-active is dead code (never applied)
  • .code-content:has(.word-wrap) and .code-lines.word-wrap are duplicative (both achieve the same result)

Consider keeping only the direct selector for clarity.

♻️ Suggested simplification
-.code-content.word-wrap-active :deep(.line),
-.code-content:has(.word-wrap) :deep(.line) {
-  white-space: pre-wrap;
-  overflow-wrap: break-word;
-  max-height: none;
-  overflow: visible;
-}
-
 .code-lines.word-wrap :deep(.line) {
   white-space: pre-wrap;
   overflow-wrap: break-word;
   max-height: none;
   overflow: visible;
 }
test/nuxt/components/CodeViewer.spec.ts (2)

18-18: Weak assertion in basic rendering test.

The OR condition wrapper.find('pre').exists() || wrapper.html().includes('line') is always true because SAMPLE_HTML contains the string 'line'. This test doesn't meaningfully verify that the component rendered correctly.

♻️ Suggested improvement
-    expect(wrapper.find('pre').exists() || wrapper.html().includes('line')).toBe(true)
+    // Verify the code-lines container exists and contains our sample HTML
+    const codeLines = wrapper.find('.code-lines')
+    expect(codeLines.exists()).toBe(true)
+    expect(codeLines.html()).toContain('const x = 1')

31-33: Prefer consistent assertion approach for class checking.

The test at line 33 checks for 'word-wrap' in the raw HTML string, whilst the test at line 48 uses wrapper.find('.code-lines').classes(). Using the same approach in both tests improves consistency and reliability.

♻️ Suggested improvement for consistency
-    const html = wrapper.html()
-    // When wordWrap is true, the code-lines div should have the 'word-wrap' class
-    expect(html).toContain('word-wrap')
+    const codeLines = wrapper.find('.code-lines')
+    // When wordWrap is true, the code-lines div should have the 'word-wrap' class
+    expect(codeLines.classes()).toContain('word-wrap')

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a03437c-19a6-460f-a9e3-03164a3ccfa5

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2fc1a and 040d8be.

📒 Files selected for processing (4)
  • app/components/Code/Viewer.vue
  • app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue
  • i18n/locales/en.json
  • test/nuxt/components/CodeViewer.spec.ts

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Member

@knowler knowler left a comment

Choose a reason for hiding this comment

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

This approach doesn’t work because when the line wraps it’s adding new line numbers for the wrapped content causing the line numbers to become inaccurate for subsequent lines in a file. For a CSS solution, I think we’ll need to create some kind of grid layout where the line numbers are one column and the code is another, then when the code wraps it’ll cause the entire row to grow.

@knowler
Copy link
Member

knowler commented Mar 23, 2026

For this one, considering that there are two other PRs open on it that others have spent considerable effort on, let’s also put this on hold until I can check in with the others.

@knowler knowler added the duplicate This issue or pull request already exists label Mar 23, 2026
@MatteoGabriele
Copy link
Member

Closing this PR.

You've opened 14 PRs in a matter of minutes, which is a clear sign of automated bulk submissions with no genuine engagement.

While AI tools can be helpful for coding assistance, our project requires genuine human involvement. We've outlined this clearly in our contribution guidelines.

If you're genuinely interested in contributing to npmx.dev:

  • Engage with the community first (issues, discussions)
  • Understand the codebase and what we actually need
  • Submit thoughtful, individual PRs with your own descriptions
  • Follow up on feedback and participate in reviews
  • Use AI as a tool to assist you, not replace you

Mass-generated PRs like these won't be accepted. We welcome real contributions from developers who want to be part of our community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add word wrap to code viewer

3 participants