Address issue #376: Re-initialize task list handlers after DOM replacement#400
Merged
Conversation
When the preview body is updated via innerHTML (the DOM-replacement path used to preserve scroll position), WebKit does not re-execute script tags in the new content. This left all newly-rendered checkboxes without click handlers, so toggling them had no effect on the editor. Fix: expose the tasklist.js initialization as window.macdownInitTaskList and call it from the DOM-replacement update script, alongside the existing Prism.highlightAll() call that solves the same problem for syntax highlighting. Related to #376
Contributor
Code Coverage ReportCurrent Coverage: 60.49% 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
tasklist.jswere lost whenever the preview re-rendered via DOM replacement (body.innerHTML = …), because browsers do not re-execute<script>tags injected throughinnerHTMLwindow.macdownInitTaskListso it can be called explicitly after each DOM replacement, matching the existing pattern used for Prism (Prism.highlightAll())breakstatement in the inner loop, which intentionally prevents duplicate handlers from being attached to nested checkboxesRelated Issue
Related to #376
Manual Testing Plan
- [ ] taskand- [x] done[x][ ]- [ ] parent\n - [ ] child) and confirm depth-first index ordering works correctlyReview Notes
The root cause and fix are analogous to the Prism syntax highlighting re-initialization already present in the same DOM-replacement script. No new unit tests were added; the toggle logic and security token validation are covered by existing tests in
MPCheckboxToggleTests.mandMPScrollSyncTests.m.