Skip to content

feat: added line and word counter to editor status bar#474

Open
harshiyasaxena wants to merge 1 commit into
piyushdotcomm:mainfrom
harshiyasaxena:feature/editor-line-word-counter
Open

feat: added line and word counter to editor status bar#474
harshiyasaxena wants to merge 1 commit into
piyushdotcomm:mainfrom
harshiyasaxena:feature/editor-line-word-counter

Conversation

@harshiyasaxena
Copy link
Copy Markdown

@harshiyasaxena harshiyasaxena commented Jun 4, 2026

Summary

  • Added dynamic line count display to the editor status bar
  • Added dynamic word count display to the editor status bar
  • Counts update automatically based on the content of the currently active file
  • Integrated the feature into the existing status bar UI without affecting existing functionality

Why it changed

The editor currently does not provide basic text statistics. This enhancement improves usability by giving users quick insights into the size of the file they are working on directly from the footer/status bar.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Test or CI improvement
  • Starter template change

Related issue

Closes #386

Validation

  • npm run lint
  • npm test
  • npm run build

List any additional manual verification you performed:

  • Verified that line count updates when adding or removing lines
  • Verified that word count updates when editing file content
  • Verified that counts are displayed correctly in the status bar
  • Verified that existing status bar information (cursor position, language, container status, etc.) remains unaffected

Checklist

  • I kept this PR focused on one primary change
  • I updated documentation if behavior changed
  • I did not commit secrets, local logs, or scratch files
  • I am requesting review on the correct scope

Summary by CodeRabbit

  • New Features
    • The editor status bar now displays real-time document metrics, including line count and word count for the currently active file. These metrics are updated dynamically as you edit and appear alongside the existing cursor position indicator, providing a quick overview of your document's scope.

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

👋 Thanks for opening a PR, @harshiyasaxena!

Your PR has entered the 🚦 PR Review Pipeline.

Standard PR detected — your PR will follow the standard review pipeline.


What happens next

Stage Reviewer Checks
Stage 1 — Automated Validation 🤖 Bot DCO · Format · AI/Slop · Duplicate
Stage 2 — Human Review 👥 Maintainer Code + Quality Review
Stage 3 — PA / Maintainer Review 🔑 Project Admin Final Merge Decision

A pipeline status comment will appear below and update automatically as your PR progresses.


While you wait

  • Sign all commits (git commit -s)
  • Link your issue (Closes #123)
  • Use a feature branch (not main)
  • Avoid unrelated changes

This comment is posted only once.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Walkthrough

EditorArea now calculates line and word counts from the currently active file's content and passes these metrics to StatusBar. StatusBar extends its props type to accept both values and renders them in the status footer alongside the existing cursor position indicator.

Changes

Document Metrics in Status Bar

Layer / File(s) Summary
Metrics calculation and props contract
modules/playground/components/status-bar.tsx, modules/playground/components/editor-area.tsx
StatusBarProps is extended with lineCount and wordCount fields. EditorArea derives these metrics from the active file's text content and wires them into StatusBar props. A minor async fallback adjustment is also applied to the preview container wiring.
Status bar metrics display
modules/playground/components/status-bar.tsx
StatusBar destructures the new metric props and renders them in the footer's left section, displaying "{lineCount} Lines" and "{wordCount} Words" alongside the cursor position indicator.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Lines now counted, words displayed with care,
The status bar shows metrics everywhere,
From file to footer, the numbers flow,
Each keystroke counted in the editor's glow! 📊✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding a line and word counter feature to the editor status bar.
Description check ✅ Passed The description includes all key sections: summary of changes, reason for change, type of change (new feature), related issue, validation steps, and a comprehensive checklist.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #386: dynamic line count calculation, dynamic word count calculation, real-time updates as users type, and integration with existing UI.
Out of Scope Changes check ✅ Passed All changes are scoped to the feature requirements: line/word count displays in status bar components with no unrelated modifications to other functionality.

✏️ 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
Copy Markdown

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
modules/playground/components/editor-area.tsx (1)

81-90: ⚡ Quick win

Memoize document metrics to avoid recomputing on cursor-only renders.

lineCount and wordCount depend on content, but they currently recalculate on every render (including frequent cursor updates). Memoizing by content keeps this path cheaper for larger files.

♻️ Proposed refactor
-import React, { useEffect } from "react";
+import React, { useEffect, useMemo } from "react";
...
-  const fileContent = activeFile?.content || "";
-
-  const lineCount = fileContent
-    ? fileContent.split("\n").length
-    : 0;
-
-  const wordCount = fileContent.trim()
-    ? fileContent.trim().split(/\s+/).length
-    : 0;
+  const fileContent = activeFile?.content ?? "";
+  const { lineCount, wordCount } = useMemo(() => {
+    if (!activeFile) return { lineCount: 0, wordCount: 0 };
+    return {
+      lineCount: fileContent.split(/\r?\n/).length,
+      wordCount: fileContent.trim()
+        ? fileContent.trim().split(/\s+/).length
+        : 0,
+    };
+  }, [activeFile, fileContent]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/playground/components/editor-area.tsx` around lines 81 - 90,
lineCount and wordCount are recomputed on every render even when only the cursor
moves; wrap their calculations in a memo keyed on activeFile?.content (e.g.,
using React.useMemo) so they only recompute when fileContent changes. Update the
logic that computes fileContent, lineCount, and wordCount (referencing
fileContent, lineCount, wordCount) to use useMemo for line/word derivation and
keep fileContent as the dependency source so cursor-only renders are cheap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/playground/components/editor-area.tsx`:
- Around line 83-85: The lineCount calculation under-reports empty active files
because it returns 0 for an empty string; update the computation in
editor-area.tsx (the lineCount variable that uses fileContent) to treat any
defined fileContent as at least 1 line — e.g. compute splitCount =
fileContent.split("\n").length and set lineCount = Math.max(1, splitCount) when
fileContent is not null/undefined, otherwise keep 0 for no active file.

---

Nitpick comments:
In `@modules/playground/components/editor-area.tsx`:
- Around line 81-90: lineCount and wordCount are recomputed on every render even
when only the cursor moves; wrap their calculations in a memo keyed on
activeFile?.content (e.g., using React.useMemo) so they only recompute when
fileContent changes. Update the logic that computes fileContent, lineCount, and
wordCount (referencing fileContent, lineCount, wordCount) to use useMemo for
line/word derivation and keep fileContent as the dependency source so
cursor-only renders are cheap.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c82b7f7-158d-4bf3-8535-127d65143b76

📥 Commits

Reviewing files that changed from the base of the PR and between f12b223 and 4fa87ec.

📒 Files selected for processing (2)
  • modules/playground/components/editor-area.tsx
  • modules/playground/components/status-bar.tsx

Comment on lines +83 to +85
const lineCount = fileContent
? fileContent.split("\n").length
: 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Empty active files are reported as 0 lines.

For newline-based counting, an empty active file should be 1 line, not 0, so the status bar currently under-reports this case.

🛠️ Proposed fix
-  const lineCount = fileContent
-    ? fileContent.split("\n").length
-    : 0;
+  const lineCount = activeFile
+    ? fileContent.split(/\r?\n/).length
+    : 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const lineCount = fileContent
? fileContent.split("\n").length
: 0;
const lineCount = activeFile
? fileContent.split(/\r?\n/).length
: 0;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/playground/components/editor-area.tsx` around lines 83 - 85, The
lineCount calculation under-reports empty active files because it returns 0 for
an empty string; update the computation in editor-area.tsx (the lineCount
variable that uses fileContent) to treat any defined fileContent as at least 1
line — e.g. compute splitCount = fileContent.split("\n").length and set
lineCount = Math.max(1, splitCount) when fileContent is not null/undefined,
otherwise keep 0 for no active file.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add Line and Word Counter in Editor Footer

1 participant