Add cursor and selection rendering for document editor#6
Merged
Conversation
- Add DocumentPosition + CursorState types (loki-text/src/editing/) - Add hit_test_document with Strategy C coordinate transform (client coords via canvas_origin computed from layout constants; offset_x/use_mounted are unimplemented in dioxus-native-dom-0.7.4) - Add CursorPaint, SelectionRect, paint_cursor to loki-vello/src/scene.rs; update paint_single_page to accept Option<&CursorPaint> - Add resolve_cursor_paint + build_selection_rects in document_source.rs; wire cursor_state through DocumentState → WgpuSurface → editor.rs - Add derive_loro_cursor stub in loro_bridge.rs (TODO: mapping from page/paragraph index to Loro block requires layout engine lookup table) - Wire onmousedown/onmousemove/onmouseup handlers in editor.rs with TODO(cursor-layout-access) placeholder for PaginatedLayout access - Add 3 cursor paint resolution tests; fix wgpu_surface_integration.rs https://claude.ai/code/session_01HqYxT4iW8phi45WQUbifpt
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 cursor positioning, selection highlighting, and hit testing for the Loki document editor. It introduces the editing layer infrastructure to track cursor state, resolve cursor positions to visual coordinates, and render the cursor line and selection highlights on the canvas.
Key Changes
New editing module (
loki-text/src/editing/):cursor.rs: DefinesCursorState(anchor/focus positions) andDocumentPosition(page/paragraph/byte offset) typeshit_test.rs: Implements canvas-coordinate to document-position hit testing using Strategy C (calculated from known layout values)Cursor state management in
editor.rs:cursor_statesignal to track anchor and focus positionsonmousedown,onmousemove, andonmouseuphandlers for click-to-place and drag-to-selectWgpuSurfacecomponent via propsCursor rendering pipeline:
DocumentStateto carry optionalcursor_stateresolve_cursor_paint()function to convertCursorStatetoCursorPaintfor a specific pagebuild_selection_rects()for single-line and multi-line selection highlighting (intra-paragraph MVP)paint_single_page()to accept and render cursor/selection data via newpaint_cursor()functionLayout integration:
layout_document()calls to setpreserve_for_editing: truewhen cursor is active (retains Parley data for hit testing)preserve_for_editing: falsein read-only mode for lighter memory footprintNew types in
loki-vello:SelectionRect: Paragraph-local highlight rectangleCursorPaint: Container for cursor rect and selection rects for a single paragraphpaint_cursor(): Renders 2-point-wide cursor line (accent color) and semi-transparent blue selection highlightsLoro bridge stub (
loki-doc-model):derive_loro_cursor()function (returnsNonein MVP; full implementation blocked on block-ID lookup table from layout engine)Implementation Details
EditorMode::Editing; read-only mode shows no cursorhttps://claude.ai/code/session_01HqYxT4iW8phi45WQUbifpt