Repository navigation
Focus and cursor blink: restartBlink, cursorBlinkRate, onBlur shift reset (Refs #50) - #89
DJAscendance wants to merge 8 commits into
Conversation
) cursorCoords/charCoords/coordsChar/lineAtHeight/heightAtLine method forms (cursor_coords_in, char_coords_in, coords_char_in, line_at_height_in, height_at_line_in) with page and window modes over a host-supplied window origin and page scroll, start=null/true/false, clipPos, LineHandle arguments, includeWidgets (no widgets yet) and the end-of-document adjustment; intoCoordSystem/fromCoordSystem ported with CM5's div (viewOffset) semantics. The port's internal document-y frame is now CoordSys::Doc. Checked against a CM5 recording (cm5-coord-systems.json).
… (Refs #54) get_scroll_info() returns CM5's {left, top, height, width, clientHeight, clientWidth}; scroll_into_view_target takes null (cursor plus cursorScrollMargin), a line number, a position, a range, a coordinate box or a box range (scrollToCoordsRange); scroll_rect_into_view is the immediate, thresholded scrollIntoView(cm, rect) helper. Checked against a CM5 recording (cm5-scroll-api.json), including scrollTo and scrollIntoView inside one operation.
NamedListeners (one copy-on-write list per event name) and cm_core::Emitter port on/off/getHandlers/signal/hasHandler for string-named and custom events on any object; the editor, documents, line handles and markers get a named table beside their typed lists. Editor::signal_dom_event and on_dom_event port signalDOMEvent; key_down, key_press, mouse_down, paste and maybeScrollWindow (scrollCursorIntoView) signal before handling, and a handler that calls prevent_default or sets codemirror_ignore pre-empts the editor.
… reset (Refs #50) The editor keeps the blink: restart_blink on focus (also when already focused), after an operation that changed the selection and after a handled key; cursor_blink_visible / next_blink_in follow the cursorBlinkRate option (> 0 blinks, 0 shows, < 0 hides). Blurring stops the blink and schedules onBlur's 150 ms display.shift reset, run by the host through run_timers / next_timer_in. The native window draws and wakes from these instead of its fixed 530 ms timer.
into_coord_system honors include_widgets as CM5 does: without it the box moves below the widgets above the line (widgetTopHeight), before the "line" early return; master's into_coords path is the include_widgets = false case. Exports keep both sides' items. New test into_coord_system_include_widgets.
Keep both listener sets (gutter/line-widget events and named events).
MiniMax-M3.1-Flash QAReview summaryThe PR is substantial and generally well structured: the new APIs are backed by CM5 recordings, named-event behavior has focused regression coverage, and the coordinate/scroll work includes both implementation tests and oracle-generation scripts. I found one likely functional issue and a couple of smaller robustness concerns. Findings
Validation recommendationsBefore merging, I would run: I would also add a targeted regression test for operation ordering of coordinate-form |
Refs #50
Ledger rows: 615 onFocus, 616 onBlur, 679 restartBlink.
Base:
7d917785a1b65259b238f35a3fad98343d8a6d02(master, merged in); parent PR head910c2e085efcd7cd883b5f79dd72b1391fbf8376Head:
941d6c6cfcf4eebc4b4d0e36a9386def958def99Integration: Stacked on #86 (
910c2e0); merge in order #81, #83, #86, #89, #90, #91, #92. Until the PR below it merges, this PR's diff against master includes that PR.What this adds
EditorOptions::cursor_blink_rate(cursorBlinkRate, default 530).Editor::restart_blink()(restartBlink). While the editor is focused, the blink period starts again now. It is called:set_focused(true), every time, including when the editor is already focused (onFocus ends with restartBlink);op.selectionChanged, operations.js:127);Editor::cursor_blink_visible()follows the rate: a rate > 0 toggles every rate ms, 0 shows the cursor without blinking, and a negative rate hides it. An unfocused editor shows no cursor (CM5's CSS).Editor::next_blink_in()tells the host when to wake up.set_focused(false)stops the blinker and schedules onBlur's 150 msdisplay.shiftreset, which is skipped if the editor is focused again in time.Editor::run_timers()andnext_timer_in()are the host timer hooks.window.rs) draws the cursor and schedules wake-ups from these, instead of its fixed 530 msInstanttimer. It tells the editor it is focused when the app opens, and runsrun_timerswhen idle.Upstream refs (pinned 4ca3d05)
src/display/focus.js:21-50; src/display/selection.js:160-174; src/display/operations.js:127; src/edit/key_events.js:74-77; src/edit/options.js:156.
Tests and evidence
crates/cm-view/tests/focus_blink.rsruns on a host clock (cm_core::clock::set_override):blink_follows_focus_and_rate: toggles at the exact rate boundaries, restarts on a selection-changing operation and on a handled key, and does not restart on an empty operation.blink_rate_zero_and_negativeblur_resets_shift_after_150ms: the 149/150 ms boundary, refocus cancels the reset, and a repeated focus restarts the blink without a secondfocusevent.app_script.rs::winit_event_loop_under_xvfb(the native window) passes.0b167ad, which contains this PR and every PR below it):cargo test --workspace --no-fail-fastgave 834 passed, 0 failed, 0 ignored. The same underxvfb-run -a: 834 passed, 0 failed.tools/web-test.sh: all 5 browser profiles passed 63/63.Dom::restart_blink,setCursorBlinkRate), which matches CM5 but does not read the engine option.Known differences
focus/blurbefore it changesstate.focused. The port changes the state first (unchanged by this PR).delayingBlurEvent/draggingText, readOnly"nocursor"(the port'sread_onlyis a bool), and the hidden-input reset on focus.onBlur(cm)(which only schedules the shift reset) is not modeled.Coverage change
CI: pending (Actions cannot start: billing)