Address issue #452: Selection character/word count#460
Merged
Conversation
When the editor has a non-empty selection, the bottom count widget now shows the selection's words, characters, and characters-without-spaces (each title carries a "selected" indicator). When the selection is empty it reverts to the document-wide totals. - Expose MPTextCountForString() so the editor can count its selected substring using the same algorithm as the document-wide word count. - Observe NSTextViewDidChangeSelectionNotification and swap the widget titles via a showingSelectionCount flag; document-total setters keep storing values but skip title writes while a selection is shown so a throttled updateWordCount can't clobber the selection display. - Add localized "… selected" plural strings (en). - Add MPSelectionCountTests covering the pure counting logic and the display-mode coordination. Related to #452
Make the bare-document path explicit instead of relying on a struct return from a nil receiver, so editorSelectionDidChange: is well-defined before the nib loads. Related to #452
Related to #452
Contributor
Code Coverage ReportCurrent Coverage: 60.76% Coverage Details (Summary) |
schuyler
added a commit
that referenced
this pull request
Jul 1, 2026
## Summary PR #460 added a selection character-count feature to the word-count widget and introduced three new plural string keys, but only in `en.lproj`. In any other locale, `NSLocalizedString` returns the **key name** (not an English fallback) when the key is absent, so `JJPluralForm` can't parse it and the widget shows **"ERR"** when text is selected. Reported by rcuisnier in French during rc.1 testing. This adds the three keys to all 25 non-English locales: - `WORDS_SELECTED_PLURAL_STRING` - `CHARACTERS_SELECTED_PLURAL_STRING` - `CHARACTERS_NO_SPACES_SELECTED_PLURAL_STRING` ## Approach Each locale's translation was built from its **existing** base plural vocabulary (`WORDS_PLURAL_STRING`, etc.) plus the word for "selected," with grammatical agreement matched per language — gender/number in Romance, Slavic, Hebrew, Arabic, Icelandic; case agreement in Finnish; invariant participles where appropriate (German, Dutch, Turkish, Hindi, CJK). The two-form `"%@ singular;%@ plural"` structure and `JJ_PLURAL_FORM_RULE = "1"` convention are preserved. A few forms were refined after review: - **Japanese** uses the state form `選択中` ("currently selected") rather than a verb reading as a command. - **Arabic / Hebrew** place the participle adjacent to the noun; Hebrew uses `מסומן` ("marked/selected") with correct final-vs-medial nun across gender/number. ## Verification - `grep -L` confirms all 25 non-English files now contain the keys; none missing. - `en.lproj` unchanged; no existing keys altered; only the three additions per file (`25 files changed, 175 insertions`). - Non-Latin strings decoded to Unicode codepoints to confirm correct letters and logical byte order (independent of terminal shaping/BiDi). Related to #452
schuyler
added a commit
that referenced
this pull request
Jul 1, 2026
## Summary PR #460 added a selection character-count feature to the word-count widget and introduced three new plural string keys, but only in `en.lproj`. In any other locale, `NSLocalizedString` returns the **key name** (not an English fallback) when the key is absent, so `JJPluralForm` can't parse it and the widget shows **"ERR"** when text is selected. Reported by rcuisnier in French during rc.1 testing. This adds the three keys to all 25 non-English locales: - `WORDS_SELECTED_PLURAL_STRING` - `CHARACTERS_SELECTED_PLURAL_STRING` - `CHARACTERS_NO_SPACES_SELECTED_PLURAL_STRING` ## Approach Each locale's translation was built from its **existing** base plural vocabulary (`WORDS_PLURAL_STRING`, etc.) plus the word for "selected," with grammatical agreement matched per language — gender/number in Romance, Slavic, Hebrew, Arabic, Icelandic; case agreement in Finnish; invariant participles where appropriate (German, Dutch, Turkish, Hindi, CJK). The two-form `"%@ singular;%@ plural"` structure and `JJ_PLURAL_FORM_RULE = "1"` convention are preserved. A few forms were refined after review: - **Japanese** uses the state form `選択中` ("currently selected") rather than a verb reading as a command. - **Arabic / Hebrew** place the participle adjacent to the noun; Hebrew uses `מסומן` ("marked/selected") with correct final-vs-medial nun across gender/number. ## Verification - `grep -L` confirms all 25 non-English files now contain the keys; none missing. - `en.lproj` unchanged; no existing keys altered; only the three additions per file (`25 files changed, 175 insertions`). - Non-Latin strings decoded to Unicode codepoints to confirm correct letters and logical byte order (independent of terminal shaping/BiDi). Related to #452
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a live count of the current editor selection to the existing bottom count widget. When text is selected, the widget shows the selection's words, characters, and characters (no spaces) — each title carrying a "selected" indicator. When the selection is empty, it reverts to the document-wide totals exactly as before.
This lets users writing length-limited content (e.g. command entries) verify selection length without leaving the app.
Approach
editorShowWordCountpreference and reuses the existing localized plural-string machinery.MPTextCountForString()wrapper over the same per-string algorithm used for the document-wide count, guaranteeing consistent results.showingSelectionCountflag ensures a throttled documentupdateWordCountcannot clobber the selection display; document-total setters keep storing values but skip title writes while a selection is shown.Changed files
MacDown/Code/Extension/DOMNode+Text.{h,m}— exposeMPTextCountForString().MacDown/Code/Document/MPDocument.m— observeNSTextViewDidChangeSelectionNotification; addeditorSelectionDidChange:/refreshDocumentWordCountTitles; refactor count-title writing intoselected:-aware helpers; nil-editor guard; reset selection mode when the preference is disabled.MacDown/Localization/en.lproj/Localizable.strings— three new "… selected" plural keys (other locales fall back to English until translated).MacDownTests/MPSelectionCountTests.m(new, wired into the Xcode project) — unit tests for the pure counting logic and display-mode coordination.CHANGELOG.md— Unreleased entry.Related Issue
Related to #452
Manual Testing Plan
Review Notes
MPGetStringAccumulatedTextCountso selection and document counts use the same algorithm.Generated by Claude Code