mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-03 21:32:25 -06:00
## TL;DR: For custom-init markdown editors, do nothing. For non-custom-init markdown editors, change from an imperative scan to a declarative setup. ## Longer version As part of the `data-global-init` migration effort, this moves ComboMarkdownEditor's automatic setup onto `data-global-init`. ### Before `initGlobalComboMarkdownEditor()` ran a one-off startup sweep of its own: `queryElems(document, '.combo-markdown-editor:not(.custom-init)', ...)`. The editor template relied on that page-wide selector, with the `custom-init` class as an exclusion, rather than declaring its own setup. ### After - The editor template marks its root element with `data-global-init="initComboMarkdownEditor"`, and the sweep is replaced by a registered handler, like other migrated components. - The attribute goes only on editors without `CustomInit`. `CustomInit` editors are unchanged: they get no attribute, and their page code sets them up as before. - Setup now goes through the shared observer, so the editor follows the same rules as every other `data-global-init` component, including elements added after page load. ### Why - The template now names its own setup: `data-global-init="initComboMarkdownEditor"` leads straight to the registered handler. Before, nothing in the template said how the editor was set up, and the `custom-init` class only meant something because of a selector in `common-form.ts`. - It follows the guidance in `modules/observer.ts`, which recommends `registerGlobalInitFunc` over selector-based setup as "less efficient and less maintainable", and removes one of the `queryElems(document, ...)` sweeps that `utils/dom.ts` marks for refactoring. - The editor no longer needs its own page-wide query at startup: it's picked up by the observer's single initial pass, like the other `data-global-init` components (55 templates use it today). ### Notes - Editors are now set up by the observer's initial sweep, which runs after the page-specific init code rather than before it. Every direct editor lookup (`getComboMarkdownEditor` in `repo-release.ts`, `repo-issue-edit.ts`, `repo-issue.ts` and the monospace toggle in `ComboMarkdownEditor.ts`) runs on a user action, so none is affected. - This is the first step toward removing `CustomInit` entirely. That also needs JS-only options moved into presets and setup made idempotent, which are separate changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>