|
| 1 | +# Instructions |
| 2 | + |
| 3 | +This file provides guidance to coding agents when working with code in this repository. |
| 4 | + |
| 5 | +## General Approach |
| 6 | + |
| 7 | +- Analyze assumptions and provide counterpoints — prioritize truth over agreement. |
| 8 | +- Treat me as an expert Android developer. Give overviews, not tutorials. |
| 9 | +- Always give an overview of the solution before diving into implementation (unless explicitly asked to implement right away). |
| 10 | +- Do not add comments for trivial logic or when the name is descriptive enough. |
| 11 | + |
| 12 | +## Architecture Overview |
| 13 | + |
| 14 | +**AztecEditor-Android** is a rich-text HTML editor library for Android, built on the `EditText` / `Spannable` API. |
| 15 | + |
| 16 | +**Stack**: Kotlin, Android Spannable API, Plugin architecture, Gradle with Kotlin DSL |
| 17 | + |
| 18 | +### Module Structure |
| 19 | + |
| 20 | +``` |
| 21 | +:app — Demo application |
| 22 | +:aztec — Core editor library (main deliverable) |
| 23 | +:glide-loader — Image loading via Glide |
| 24 | +:picasso-loader — Image loading via Picasso |
| 25 | +:wordpress-comments — WordPress comments plugin |
| 26 | +:wordpress-shortcodes — WordPress shortcodes plugin |
| 27 | +:media-placeholders — Media placeholders with Compose support |
| 28 | +``` |
| 29 | + |
| 30 | +All plugin/loader modules depend on `:aztec`. Published independently to Automattic S3 Maven (`org.wordpress:aztec`, `org.wordpress.aztec:*`). |
| 31 | + |
| 32 | +### Code Navigation (package: `org.wordpress.aztec`) |
| 33 | + |
| 34 | +| To find... | Look in... | |
| 35 | +|---------------------------------|------------------------------------------------------| |
| 36 | +| Main editor component | `aztec/.../AztecText.kt` (extends EditText, ~3K LOC) | |
| 37 | +| Editor facade / initialization | `aztec/.../Aztec.kt` | |
| 38 | +| HTML parsing | `aztec/.../AztecParser.kt`, `AztecTagHandler.kt` | |
| 39 | +| Custom spans (visual rendering) | `aztec/.../spans/` (62 files — one per HTML element) | |
| 40 | +| Text formatting logic | `aztec/.../formatting/` (Block, Inline, Line, List) | |
| 41 | +| Block element handlers | `aztec/.../handlers/` (Heading, List, Quote, etc.) | |
| 42 | +| Plugin interfaces | `aztec/.../plugins/` (IAztecPlugin, IToolbarButton) | |
| 43 | +| HTML source editor | `aztec/.../source/SourceViewEditText.kt` | |
| 44 | +| Text change watchers | `aztec/.../watchers/` (30+ files, API-version buckets)| |
| 45 | +| Toolbar | `aztec/.../toolbar/AztecToolbar.kt` | |
| 46 | +| Undo/redo | `aztec/.../History.kt` | |
| 47 | +| Compose placeholders | `media-placeholders/.../ComposePlaceholder*.kt` | |
| 48 | + |
| 49 | +### Key Architectural Patterns |
| 50 | + |
| 51 | +1. **Span-based rendering** — Each HTML element has a custom `Span` class. Spans carry both visual rendering and semantic meaning. The `Spannable` API is central to everything. |
| 52 | + |
| 53 | +2. **Plugin architecture** — `IAztecPlugin` with sub-interfaces (`IToolbarButton`, `IClipboardPastePlugin`, `IOnDrawPlugin`). Plugins for `html2visual` and `visual2html` conversion pipelines. |
| 54 | + |
| 55 | +3. **Facade pattern** — `Aztec` class provides a builder-like fluent API to wire up editor, toolbar, source view, and plugins. |
| 56 | + |
| 57 | +4. **Handler/Formatter split** — Handlers deal with block element structure (headings, lists, quotes). Formatters apply styling (inline, block, line-block, list, link, indent). |
| 58 | + |
| 59 | +5. **Bidirectional HTML conversion** — HTML string <-> Spannable representation, with plugin hooks at each stage. |
| 60 | + |
| 61 | +6. **Watcher pattern** — Multiple `TextWatcher` implementations with API-version-specific buckets (API 25, 26+) for Samsung/OEM compatibility. |
| 62 | + |
| 63 | +### Common Crash Patterns (from recent PRs) |
| 64 | + |
| 65 | +- `IndexOutOfBoundsException` from span start/end being out of bounds — always clamp to `[0, text.length]` |
| 66 | +- `IllegalArgumentException` when span end < span start — validate before applying |
| 67 | +- Samsung/custom emoji OEM issues causing unexpected span states |
| 68 | +- Thread safety in `AztecAttributes` — operations should be synchronized |
| 69 | + |
| 70 | +## Git Operations (CRITICAL) |
| 71 | +- **NEVER commit without explicit permission** |
| 72 | +- **NEVER push without explicit permission** |
| 73 | +- **NEVER create a PR without explicit permission** |
| 74 | +- When asked to "fix" or "update" something, that does NOT imply permission to commit/push |
| 75 | +- Always wait for explicit "commit", "push", or "create PR" commands |
| 76 | +- Do not create branches, rebase, or modify git history unless explicitly asked |
| 77 | + |
| 78 | +## Build Commands |
| 79 | + |
| 80 | +```bash |
| 81 | +# Build and run the demo app |
| 82 | +./gradlew :app:installDebug && adb shell am start -n org.wordpress.aztec/org.wordpress.aztec.demo.MainActivity |
| 83 | + |
| 84 | +# Build the demo app (without installing) |
| 85 | +./gradlew :app:assembleDebug |
| 86 | + |
| 87 | +# Build the library |
| 88 | +./gradlew :aztec:assembleRelease |
| 89 | + |
| 90 | +# Lint (ktlint + Android lint) |
| 91 | +./gradlew ktlint |
| 92 | +./gradlew lintRelease |
| 93 | + |
| 94 | +# Unit tests (core library) |
| 95 | +./gradlew aztec:testRelease |
| 96 | + |
| 97 | +# All unit tests |
| 98 | +./gradlew testRelease |
| 99 | + |
| 100 | +# Specific test class |
| 101 | +./gradlew :aztec:testReleaseUnitTest --tests "org.wordpress.aztec.AztecParserTest" --info |
| 102 | + |
| 103 | +# Specific test method |
| 104 | +./gradlew :aztec:testReleaseUnitTest --tests "org.wordpress.aztec.AztecParserTest.testMethodName" --info |
| 105 | +``` |
| 106 | + |
| 107 | +### Build Configuration |
| 108 | + |
| 109 | +- All Kotlin warnings are errors (`allWarningsAsErrors = true`) |
| 110 | +- Versions are defined in root `build.gradle` — check there for current Kotlin, AGP, SDK, and dependency versions |
| 111 | + |
| 112 | +## GitHub Commands |
| 113 | + |
| 114 | +```bash |
| 115 | +PAGER=cat gh pr list |
| 116 | +PAGER=cat gh pr view <NUMBER> |
| 117 | +PAGER=cat gh pr view <NUMBER> --comments |
| 118 | +PAGER=cat gh pr diff <NUMBER> |
| 119 | +``` |
| 120 | + |
| 121 | +## PR Template |
| 122 | + |
| 123 | +PRs follow this format (from `.github/PULL_REQUEST_TEMPLATE.md`): |
| 124 | +``` |
| 125 | +### Fix |
| 126 | +<description of what was fixed/added> |
| 127 | +
|
| 128 | +### Test |
| 129 | +1. Step 1 |
| 130 | +2. Step 2 |
| 131 | +
|
| 132 | +### Review |
| 133 | +@reviewer |
| 134 | +``` |
| 135 | + |
| 136 | +## Skills |
| 137 | + |
| 138 | +| Skill | Trigger phrases | |
| 139 | +|-------------|------------------------------------------------------------------------------------------------------| |
| 140 | +| `implement` | "implement", "fix this", "work on this", "build this", "add feature", any implementation request | |
0 commit comments