Enable checkbox support by default with interactive toggle#270
Merged
Enable checkbox support by default with interactive toggle#270
Conversation
This commit implements GitHub issue #269, adding: 1. **Enable checkbox/task list by default** - Added one-time migration in MPPreferences.m that enables htmlTaskList for all users who haven't explicitly set a preference (following the pattern from #268). 2. **Interactive checkboxes** - Clicking a checkbox in the preview now toggles its state in the source document: - Modified hoedown_html_patch.c to add data-checkbox-index attribute - Updated tasklist.js with click handlers using custom URL scheme - Added handleCheckboxToggle: and toggleCheckboxAtIndex:inMarkdown: methods in MPDocument.m to handle the toggle logic 3. **Comprehensive tests** - Added TDD tests covering: - Migration behavior (MPPreferencesTests.m) - Checkbox index rendering (MPMarkdownRenderingTests.m) - Toggle logic and edge cases (MPCheckboxToggleTests.m) 4. **Updated golden files** - Updated task-lists.html and mixed-complex.html to include the new data-checkbox-index attributes. Related to #269
Updated task-lists.html and mixed-complex.html golden files to use the correct checkbox indices. Hoedown processes nested lists in depth-first order (children before parent), so the indices reflect that: children get lower indices than their parent element. Related to #269
Code review identified a critical bug: the toggle function used document order (line by line) but hoedown assigns checkbox indices in depth-first order (nested children before parent). This meant clicking a nested checkbox would toggle the wrong one. Changes: - Rewrote toggleCheckboxAtIndex: to use depth-first ordering via a stack-based algorithm that matches hoedown's rendering behavior - Changed regex to only match lowercase [x] (hoedown ignores capital X) - Added thread-safety documentation to the global counter - Added tests for parent checkbox toggling and depth-first ordering Related to #269
Contributor
Code Coverage ReportCurrent Coverage: 52.22% 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
This PR implements GitHub issue #269 (Render Check Boxes feature request) with the following enhancements:
Implementation Details
Migration (MPPreferences.m)
One-time migration enables
htmlTaskListfor users who haven't explicitly disabled it.Checkbox Indexing (hoedown_html_patch.c)
Added
data-checkbox-indexattribute to rendered checkboxes. Indices are assigned in depth-first order to match hoedown's nested list rendering behavior.Click Handling (tasklist.js)
Checkboxes are now clickable. Clicks trigger a custom URL scheme (
x-macdown-checkbox://toggle/N) that communicates back to the Objective-C code.Toggle Logic (MPDocument.m)
The
toggleCheckboxAtIndex:inMarkdown:method locates and toggles the specified checkbox in the source document, using depth-first ordering to match the rendered HTML indices.Test Plan
Code Review Issues Addressed
Fixed critical bug identified during code review: the toggle function originally used document order indexing, but hoedown assigns indices in depth-first order (nested items before parent). This mismatch would have caused the wrong checkbox to be toggled in nested lists.
Related to #269