Fix Issue #294: Update word count during DOM replacement#296
Merged
Conversation
The word count was only updating after full WebView reloads via didFinishLoadForFrame:, but the DOM replacement optimization path (used for most edits) skipped this callback entirely. Changes: - Add scheduleWordCountUpdate method with debouncing (300ms) to avoid performance issues during rapid typing - Call scheduleWordCountUpdate in the DOM replacement path - Add wordCountUpdateQueue NSOperationQueue for debouncing - Cancel pending updates on document close to prevent crashes - Add unit tests for the new functionality Related to #294 https://claude.ai/code/session_01K3sCpwVKwQZQmndbHxA829
Skip testWordCountUpdateQueueInitializedAfterWindowSetup when running in headless CI mode where windowControllerDidLoadNib is not called. Related to #294 https://claude.ai/code/session_01K3sCpwVKwQZQmndbHxA829
- Use NSBlockOperation with isCancelled check after sleep to properly cancel pending operations (fixes race condition where cancelled operations would still dispatch updateWordCount) - Add nil check for wordCountUpdateQueue before use - Add queue name for debugging Related to #294 https://claude.ai/code/session_01K3sCpwVKwQZQmndbHxA829
Add MPWordCountUpdateTests.m to the test files inventory and update the partial coverage section to document word count testing. Related to #294 https://claude.ai/code/session_01K3sCpwVKwQZQmndbHxA829
Contributor
Code Coverage ReportCurrent Coverage: 54.11% Coverage Details (Summary) |
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
The word/character count in the status bar was not updating during normal editing because the DOM replacement optimization path (used for most edits) skipped the
didFinishLoadForFrame:callback whereupdateWordCountwas called.Changes:
scheduleWordCountUpdatemethod with 300ms debouncing using NSBlockOperationwordCountUpdateQueueNSOperationQueue for managing debounced updatesisCancelledafter sleep delayscheduleWordCountUpdatein the DOM replacement pathclosemethod to cancel pending operationsRelated Issue
Related to #294
Manual Testing Plan
Prerequisites
Test Scenarios
1. Basic Word Count Updates
2. Rapid Typing (Debouncing)
3. Editing Operations
4. Preference Toggle
5. Preview Pane Hidden
Edge Cases
Review Notes