Commit Graph

53 Commits

Author SHA1 Message Date
16c39f4221 doc: note GlyphLayout window-relative offset invariant
Add the invariant that GlyphLayout offsets are relative to
IMEWindowStartByte and that cursor positioning must add/subtract the window
base. Record the second tap-to-cursor fix (base offset) alongside the earlier
tapLocalY fix in the development plan.
2026-08-16 20:59:42 -04:00
6dedffcba7 editor: fix tap-to-position-cursor clamping on large files
Tapping in the editor repositions the cursor, but it was never actually
verified (the old unit test only checked in-bounds/no-panic). On-device
verification found that on a large file scrolled deep, the cursor clamped to
the bottom of the viewport regardless of tap position.

Root cause: the tap handler computed the tap's text-local Y in content space
(pt.Y - region.Y + full ScrollOffset) and passed it to SetCursorFromPoint,
whose visualLine = y/lineHeight then produced a huge content-line number
(e.g. 91,640). But the GlyphLayout is window-relative (layout.Y==0 is the top
of the visible window), so the number far exceeded the window's line count and
clamped to the last group (bottom line). The Phase 3 windowing refactor
introduced the windowed layout without updating the tap handler.

Fix: tapLocalY() converts the tap Y to window-relative space by adding only the
sub-line remainder (ScrollOffset mod lineHeight), never the full scroll.
Extracted as a named helper so it is unit-testable. Added two regression tests
that fail on the pre-fix formula (cursor clamps to the bottom line) and pass on
the fix. Verified on-device: taps now map linearly across the viewport.

Also removed the per-tap/per-glyph log.Printf debug lines in SetCursorFromPoint.
2026-08-16 17:38:24 -04:00
be48ad8157 perf: default-off in-app profiler + debug scroll jumps; verify scroll perf & clamping
internal/perf: single-goroutine profiler (no locks). When enabled by the
/storage/emulated/0/PadPerf/enable marker it records one CSV row per logic
frame (seq, ms, frame delta, page, scroll Dp, max-scroll Dp, total lines,
visible byte range), logs a rolling ~1/s summary, and on Stop reports
nearest-rank p50/p90/p99/max. Flushes per row-batch but never fsyncs per
flush (avoids periodic hitches in the logic path).

editor: PerfRecord package-level hook (nil when off) + ProbeRecord;
Logic.emitFrame() now centralizes every frame emission so the profiler sees
each logic frame exactly once, on the owner goroutine. State gains
VisibleStart/VisibleEnd so the probe can confirm shaping stays
viewport-bounded.

logic: optional debug cmd poller (off by default) watches <dir>/cmd as a
one-shot file (top/bottom/frac <0..1>/dp <int>) and the owner applies a
clamped [0,MaxScroll] jump + frame. Enables deterministic large-offset scroll
tests without pixel taps.

main: wires the profiler when the marker file exists; logs present-fps
every 2s; stops the profiler on Destroy.

docs: README package inventory (add internal/perf); architecture §11
profiler facility; spec §5 invariant 7 (scroll always clamped to
[0,maxScroll]) + §6 measured rows; development_plan v5 + Phase 6 results.

Verified: go build/vet + full -race green. On-device 10 MB file:
logic-frame cadence flat across offsets 0.02->1.0 (no large-offset
degradation), visible byte range <=4.3 KB at every offset, clamping exact
across 2->130,955-line files, PSS plateaus ~250 MB (bounded, no leak);
profiler overhead negligible.
2026-08-16 16:53:28 -04:00
5271092c21 Doc: correct frame-timing tooling — gfxinfo unusable (SurfaceView), use in-app frame deltas 2026-08-16 13:31:10 -04:00
d3d11b5d20 Doc: reorganize — delete over-detailed docs, rewrite spec + architecture to match code
- Deleted (drift-prone point-in-time plans / dead specs):
  browser_implementation_plan.md, editor_implementation_plan.md,
  virtual_scroll_render_optimization.md, conflict_resolution.md,
  touch.md, element_model.md, layout_rendering.md, bugs.txt
- Rewrote architecture.md: single-owner/no-lock model, channel topology,
  Frame handoff contract, ownership rules, editor/browser/render internals,
  active vs dead task types, testing hooks.
- Rewrote spec.md: actual behavior (browser, editor, IME, autosave, 50 MB
  limit with measured numbers), actual code layout, invariants to preserve,
  explicit deferred-features table (undo, restoration, sync awareness).
- Added doc/README.md: doc index, documentation policy, build/install
  recipe, on-device observation loop.
- Updated development_plan.md: Phase 5 mostly done; §7 spec deltas written
  with two corrections (no undo at all; no external-change detection).
2026-08-16 13:22:21 -04:00
c2918fa7c1 Doc: mark IME rapid-commit desync fixed (snippet/selection dedup) 2026-08-16 13:01:02 -04:00
4ee72cf848 Doc: mark Phase 3 complete (10 MB validated, shaper leak fixed, 50 MB limit) 2026-08-16 12:18:01 -04:00
4cfabec7a4 Doc: record Phase 2 on-device IME validation (PASSING) + 3 bugs found
- IME commit path validated on emulator (Gboard/API 35): single-char,
  multi-char (human cadence), deletion (deleteSurroundingText->EditEvent),
  and Unicode all commit correctly with cursor in sync; autosave persists.
- Build recipe scripted (gogio + apktool MANAGE_EXTERNAL_STORAGE + apksigner).
- Bugs: (1) open-file crash via Termux bridge -> fixed (c9c0d47); (2) viewport
  opens at EOF because the opening tap leaks into the editor (open, Phase 3);
  (3) rapid synthetic IME commits desync via per-frame snippet re-push (edge).
2026-08-16 09:45:51 -04:00
92d8a6b7f0 Doc: mark Phase 1 (IME) done; record chunked-buffer fixed-slot drift risk 2026-08-16 02:45:09 -04:00
21bd9fe02e Doc: mark Phase 0 done; record single-owner refactor and vision status 2026-08-16 01:33:39 -04:00
def4cec498 Development plan v2: pivot to completing the live path (IME wiring gap)
v1 (widget rebuild) was drafted against a stale snapshot. The live repo
already has the real filesystem, the Android APK, and a chunked buffer
(the 10 MB+ approach widget.Editor cannot do). The Android IME is
reachable from the op layer with only a small, precisely-defined gap:
missing key.SelectionCmd/SnippetCmd, an EditEvent handler that ignores
Range (corrupts swipe/autocorrect replacement commits), and a missing
InputHint. Completing those is now Phase 1; the emulator (now available
on the 16 GB VM) is the verification instrument.
2026-08-15 22:44:53 -04:00
03fb63863c Fix test build after NewLogic signature change; add development plan draft
NewLogic now takes (FileSystem, path, openfunc); update the e2e harness
and editor tests accordingly. The harness uses a no-op openfunc, matching
impl_other.go (the real app's OpenFile is a platform bridge, no-op off
Android).

Also adds doc/development_plan.md (draft, with corrections note re: the
live repo state).
2026-08-15 22:18:04 -04:00
c941a02f1a Draft virtual scroll render optimization plan. 2026-06-04 20:23:54 -04:00
93a5f879f5 feat: implement atomic writes for filesystem backend
- Add WriteFile method to mock filesystem (non-atomic path, creates files)
- Implement WriteFileAtomic in mock with temp file + rename pattern
  using .tmp/ directory, matching real filesystem semantics
- Update WriteFileTask.Execute() to use WriteFileAtomic
- Update FlushAll() to use WriteFileAtomic
- Fix mock to create files on write (matching os.WriteFile behavior)
- Update tests to match new semantics (create-if-not-exists)
2026-06-04 18:01:51 -04:00
d73cb0be2c Integrate real filesystem with interface abstraction
- Define pool.FileSystem interface in internal/io/pool/filesystem.go
- Move DirEntry interface to internal/io/pool/types/types.go to break
  the pool <-> mock import cycle
- Implement real.FileSystem with atomic writes (temp file + os.Rename)
- Update mock.FileSystem to satisfy pool.FileSystem interface
- Update worker pool tasks to accept pool.FileSystem interface
- Update main.go to use RealFileSystem by default, with -root flag
- Update all browser/editor/test references to types.DirEntry
2026-06-04 16:19:38 -04:00
ca828569f7 Fix deadlock when opening files and update E2E tests 2026-06-04 13:06:30 -04:00
d06f8af0f7 Documentation updates. 2026-06-04 08:38:11 -04:00
dbe822d3f6 Doc updates. 2026-06-03 22:51:22 -04:00
62d1f827e0 Fix cursor rendering lag and implement Enter key newline insertion 2026-06-03 20:19:35 -04:00
a5d1c4bee6 Compute glyphLayout after text rendering. Implement correct cursor
movement.
2026-06-03 19:01:05 -04:00
f515c4ec3b Documentation updates. 2026-06-03 12:01:25 -04:00
1609731ca1 doc(editor): add GlyphLayout architecture for cursor placement tracking
- Add Section 8 describing GlyphLayout data structure and feedback path
- Renderer captures byte offsets, X/Y positions, and advance widths during shaping
- Layout flows via layoutChan to logic goroutine, replacing lastLineYChan
- Editor uses layout for accurate cursor rendering and navigation
- Handles word wrap, screen resize, editing, scroll, and non-fixed-width fonts
2026-06-03 11:07:12 -04:00
bb55b4ab81 Bug fixes. 2026-06-03 10:38:29 -04:00
0dac354f2a fix(editor): wire key events to cursor movement
- Replace gtx.Event(nil) with key.Filter{Focus: focusedID} and
  key.FocusFilter{Target: focusedID} so Gio correctly routes key
  and edit events to the focused editor text field.

- Convert EditorState.CursorPosition (byte offset) to line/column
  coordinates for accurate cursor rendering.

- Add debug logging in HandleKeyDown and HandleCursorMove.
2026-06-03 07:41:18 -04:00
6709f52e0f Fix browser page scrolling by initializing EntryHeight and correcting scroll handler type assertion 2026-06-01 10:57:34 -04:00
281298ac1f Add spec.md documentation 2026-05-31 23:21:52 +00:00
86328bab5b doc: normalize SPEC.md to spec.md (case rename)
Content preserved in doc/spec.md. Lowercase naming is more
portable across case-insensitive filesystems.
2026-05-31 19:21:28 +00:00
3f1c881a06 browser: document lazy loading implementation plan
- Add detailed §15 lazy loading plan with 7 implementation steps
- Update Phase 2 checklist with specific tasks
- Add E2E test harness for browser files
- Refactor browser layout and handler structure
- Add .gitignore for common patterns

WIP: Actual lazy loading not yet implemented.
2026-05-31 18:43:46 +00:00
6a43e3c0db Add e2e test harness for testing editor logic without Gio display
- internal/test/e2e/: FrameCapture, Harness, ElementAssertions, helpers
- internal/editor/logic.go: Add done channel and Done() method for graceful shutdown
- internal/editor/mock_setup.go: Mock filesystem for tests
- internal/browser/: Browser layout and search logic
- internal/io/: Worker pool for async tasks
- Update architecture docs and spec
2026-05-31 08:56:30 -04:00
23fdeabad4 Fix scroll clipping: ListView now clips scroll gestures to its region
- Add clippableElement interface for elements that need their own clip region
- ListView implements NeedsClip() so drawElement pushes a clip before Draw
- RegisterScroll no longer has its own clip; relies on element clip context
- Aligns with Gio's clip-based gesture registration model
- Fix scroll events firing outside the visible list area on browser page

Also:
- Update touch.md documentation to reflect clip-based interaction model
- Remove debug logging from ListView.Draw
- Remove TODO-click-fixes.md (all items resolved)
2026-05-28 14:56:12 -04:00
ae04aabb70 Documentation update. 2026-05-26 10:00:14 -04:00
50e9ca5b34 Updates to rendering pipeline and documentation. 2026-05-25 17:40:35 -04:00
3fc28fd54b Document background drawing with clips — use push/pop, not op.Record macro 2026-05-09 19:17:56 -04:00
4893d69f4e Add light gray background to StatusBar and BottomBar
Rename shaper_usage.md to layout_rendering.md
2026-05-09 18:49:43 -04:00
b8c6878f46 Introduce distinct Dp/Px types to prevent coordinate mixing at compile time
- Add ui.Dp and ui.Px as distinct named types
- Logic layer works exclusively in Dp (positions, sizes, regions)
- Renderer converts Dp→Px at Gio interop boundaries
- Capture gtx.Constraints once at start of Draw() for consistent positioning
- main.go converts app.ConfigEvent pixels to Dp before passing to logic layer
- Update documentation with new coordinate system architecture
2026-05-09 18:40:47 -04:00
f563a515e6 Document BottomBar X positioning and widget constraint modification 2026-05-09 18:01:57 -04:00
3a3a62a50c Document BottomBar visible window positioning and pixel/DP conversion 2026-05-09 17:22:31 -04:00
9fd6239129 Clean up debug statements, restore proper icons, document multi-line text spacing
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-09 14:48:12 -04:00
f67cca1f4b Update shaper_usage.md with correct MinWidth/MaxWidth/MaxLines requirements and offset calculation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-09 14:07:47 -04:00
0f62ef32fa Update shaper_usage.md with correct glyph drawing approach
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-09 11:15:57 -04:00
0fdaea990f Revert to material.Label for rendering - shp.Draw() not available in Gio v0.9.0
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-09 11:02:42 -04:00
9f36806a4f Re-arrange top bar icons, move byte position to bottom bar
StatusBar (top bar):
- Icons re-arranged: [Cut] [Copy] [Paste] on left, [Conf] [Search] on right
- Removed Right/BytePosition field (moved to BottomBar)

BottomBar:
- Added BytePos field (e.g., "1024 / 50000 bytes")
- Word wrap is now a button (tap to toggle On/Off)
- Layout: CursorPos (left) | BytePos (center) | WordWrap button (right)

Element changes:
- StatusBar: removed Right field, added Search field
- BottomBar: added BytePos field, WordWrap is now a button

Interaction:
- Word wrap tap sends InputEvent{ElementID: "word_wrap"} to Logic
- Logic toggles word_wrap_enabled state field

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 15:22:12 -04:00
8b09697e6b Add search button to top bar, move cursor info to bottom bar
StatusBar (top bar):
- Added Search icon (always visible, toggles search bar)
- Removed cursor position from top bar (moved to bottom bar)
- Fixed icon slots: Cut, Copy, Search, Paste (left to right)
- File size between Paste and Conflict icons

BottomBar (new element):
- Always visible at bottom of editor page (24 DP fixed height)
- Left: cursor position (Ln X, Col Y)
- Right: word wrap status (On/Off)
- Cursor position updated on every cursor movement
- Word wrap status persisted to .pad/state.json

Search button:
- Tap toggles search bar visible/invisible
- When active: shows SearchBar element, focuses text field, shows keyboard
- When inactive: hides SearchBar, clears query, hides keyboard
- Primary search activation method on Android (Ctrl+F still works as secondary)

Layout:
- Top: StatusBar (filename + action icons)
- Middle: SearchBar (when active) + TextField (editor)
- Bottom: BottomBar (cursor position + word wrap status)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 15:13:16 -04:00
c210f9a2f1 Add cut/copy/paste with persistent clipboard and filename ellipsis toggle
Cut/Copy/Paste:
- Separate icons in StatusBar at fixed positions (no reflow)
- Clipboard persisted to .pad/clipboard.json (survives process death)
- Cut: copies to clipboard, deletes from buffer, appends to undo chain
- Copy: copies to clipboard, keeps text in buffer
- Paste: inserts clipboard text at cursor, appends to undo chain
- Visibility: Cut/Copy when selection exists, Paste when clipboard non-empty

Filename ellipsis toggle:
- Filename on separate line at top of StatusBar
- Truncated with ellipsis if too long
- Tap ellipsis toggles between truncated and full multi-line view
- filename_expanded state field (not persisted)

StatusBar layout:
- Line 1: filename (truncated or full)
- Line 2: [Cut] [Copy] Ln X, Col Y [Paste] size [Conflict]
- Fixed icon slots: Cut (left), Copy (36DP from Cut), Paste (right), Conflict (rightmost)
- Region.H computed dynamically based on filename expansion

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 15:02:00 -04:00
fdb51810f4 Add Android IME bridge via Fragment section to touch.md
- Fragment registration pattern from Passgo: app.ViewEvent → GioView → Context → Activity → FragmentManager
- IME Fragment architecture: hidden EditText in transparent Fragment overlay
- Two-way sync: Gio→EditText (cursor sync via setSelection), EditText→Gio (IME events via TextWatcher + JNI callback)
- Text window management: ±1KB around cursor, updated on cursor move and text changes
- IME feature support: autocorrect, swipe typing, voice, predictions, emoji, CJK composition
- Event merging: Main goroutine drains JNI callback channel alongside w.Event() calls
- Implementation notes: impl_android.go, jni_android.c, ime/ImeFragment.java

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 14:39:11 -04:00
e4c5804170 Add touch and input handling specification (doc/touch.md)
- Gioui primitives: pointer.InputOp, key.InputOp, key.FocusOp, SoftKeyboardOp
- Op/Event flow: Logic computes elements, Renderer submits ops, Main batches events
- Coordinate mapping: UI space → text space → byte space, with hit-region tags
- Gesture state machine: tap, double-tap, long-press, drag-select, scroll
- Gesture disambiguation: timing thresholds (500ms long-press, 300ms double-tap, 16DP drag)
- Selection logic: selection_start/selection_end byte offsets
- Input batching: Main accumulates events, sends batch to Logic per frame
- Keyboard interaction: focus acquisition/loss, key event table, IME composition
- Scroll momentum: fling logic with exponential decay, scroll clamping

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 12:01:06 -04:00
8bd9376fa9 Correct runtime architecture: batched input, config channel, frame receiver logic
- Update block diagram to show correct channel/mutex flow
- Frame receiver now calls w.Invalidate() inside the mutex lock
- Logic goroutine now waits on batched []InputEvent and configChan
- Main loop batches events and sends outside the lock
- Remove select-with-default batching from logic

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 10:56:34 -04:00
f8f81b1fec Update architecture: input batching, priority workers, memory monitoring
- Add input batching to Logic goroutine via non-blocking select loop
- Add two-tier priority queue (high/low) to Worker pool
- Add §10 Memory Monitoring and Management (heap stats, debug page, future governor)
- Update diagram and channel topology to reflect new channels

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 10:10:06 -04:00
4b048b679e Add runtime architecture specification
- New doc/architecture.md: concurrency model, goroutine responsibilities,
  channel topology, deadlock analysis, sync/async partitioning
- Update SPEC.md §3: split into code organization + runtime architecture,
  cross-reference to architecture.md

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-08 08:24:04 -04:00
485fc59e06 Spec: resolve open design decisions
- Line index: cached on disk in .pad/indices/, invalidated by mtime/size,
  incremental updates during editing sessions
- Atomic writes: temp files live in .pad/tmp/, excluded from Syncthing via .stignore
- State storage: multi-file JSON approach (state.json, cursors.json, undo/*.json)
  over SQLite — simpler, debuggable, sufficient for expected workload
- Undo limits: 1 MB inline cap on deleted field; larger deletions stored in
  separate backup files; 10 MB total disk budget for undo directory
- Added search and word wrap sections to the editor spec
- Updated performance guarantees with search/jump targets
2026-05-07 20:23:24 -04:00