Skip to content

Trac: Modernize DOM traversal and text selection methods - #1001

Open
timse201 wants to merge 1 commit into
WordPress:trunkfrom
timse201:patch-24
Open

timse201 wants to merge 1 commit into
WordPress:trunkfrom
timse201:patch-24

Conversation

@timse201

@timse201 timse201 commented Oct 3, 2026 •

Copy link
Copy Markdown

Modernize DOM traversal and text selection methods

  • Validate global regex and use native acceptNode filtering in linkTextNodes.
  • Remove legacy IE selection fallback in encloseSelection in favor of setRangeText().
  • Update wikitext textarea check to look for setRangeText().
  • Replace deprecated substr() with slice() when generating component words.

Summary by CodeRabbit

  • Bug Fixes
    • Improved wiki-toolbar formatting so wrapped text remains selected and any trailing space stays outside the formatting.
    • Updated automatic text linking to skip blank text and text already inside links.

Modernize DOM traversal and text selection methods

- Validate global regex and use native acceptNode filtering in linkTextNodes.
- Remove legacy IE selection fallback in encloseSelection in favor of setRangeText().
- Update wikitext textarea check to look for setRangeText().
- Replace deprecated substr() with slice() when generating component words.
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props timse201.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@timse201 timse201 added [Type] Enhancement New feature or request [Site] Trac labels Oct 3, 2026
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e8e64cb-d85d-45c0-8928-aae6c4a16821
📥 Commits

Reviewing files that changed from the base of the PR and between 76f89bf and 3eddcc0.

📒 Files selected for processing (1)
  • wordpress.org/public_html/style/trac/wp-trac.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The Trac JavaScript file changes text-node filtering, wiki-toolbar selection handling, and component keyword plural handling.

Changes

Trac script updates

Layer / File(s) Summary
Text and selection helpers
wordpress.org/public_html/style/trac/wp-trac.js
linkTextNodes filters out text inside links and blank text. The wiki toolbar uses setRangeText to wrap and select text, and places a trailing space after the suffix. Component keyword plural handling uses slice instead of substr.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: obenland

Merge Risk: ⚪ Minimal · up to 3eddc

The changes modernize text linking, toolbar selection wrapping, and plural handling in the Trac script. No concrete merge-blocking risk was identified.

Architecture Summary

Architecture risk: 🔵 Low · up to 3eddc

The change affects 1 system.

Changed systems: wordpress.org

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — wordpress.org (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in wordpress.org/public_html/style/trac/wp-trac.js: linkTextNodes now ignores invalid or non-global regexes and uses a TreeWalker filter to reject text within links and skip empty or whitespace-only nodes. The previous approach walked all text nodes and filtered out linked nodes afterward.
  • observed — Modified behavior in wordpress.org/public_html/style/trac/wp-trac.js: encloseSelection replaces the legacy document.selection and setSelectionRange handling with selection offsets and setRangeText, then explicitly selects the enclosed text. A trailing space is moved after the suffix. Toolbar setup now checks for setRangeText support rather than checking for the removed selection APIs.
  • observed — Modified behavior in wordpress.org/public_html/style/trac/wp-trac.js: Plural component-word generation replaces substr calls with slice to remove a trailing s.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes to DOM traversal and text selection methods.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Labels

[Site] Trac [Type] Enhancement New feature or request

Projects

Status: 👀 In review (PRs only)

Development

Successfully merging this pull request may close these issues.

1 participant