Repository navigation
Named and custom events, getHandlers, signalDOMEvent (Refs #37) - #86
DJAscendance wants to merge 6 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.
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 covered by focused CM5 oracle recordings, and the changes consistently migrate internal callers from I do not see a clearly reproducible blocking defect in the provided diff. A few areas deserve follow-up before merging. 1. Please verify the
|
Refs #37
Ledger rows: 295 on, 296 getHandlers, 297 off, 298 signal, 299 signalDOMEvent. Also 657 maybeScrollWindow (the scrollCursorIntoView veto).
Base:
7d917785a1b65259b238f35a3fad98343d8a6d02(master, merged in); parent PR head2919bd97af2043426f40b1d3558340e9bcf56959Head:
910c2e085efcd7cd883b5f79dd72b1391fbf8376Integration: Stacked on #83 (
2919bd9); 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
cm_core::events::NamedListeners<H>: one copy-on-writeListenersper event name. It provideson_rc,remove/offby id,remove_fn/off_fnby function identity per name,get_handlers(a snapshot, empty for an unknown name) andhas_handler. Its semantics are CM5's: a running signal keeps the list it started with.cm_core::EmitterisCodeMirror.on/off/signalon any object, such as an addon's hint data. Values travel asArgs = &[&dyn Any], and handlers downcast them.Editor:on_event,on_event_rc,off_event_fn,get_handlers,has_handler,signal_event. Handlers get&mut Cx.Editor::offcovers named ids too.Doc:on_event,off_event_fn,get_handlers,has_handler,signal_event.Doc::offcovers named ids.LineHandleandTextMarker:on_event,get_handlers,signal_event.offcovers named ids.signal_eventreaches it. This is documented and tested.signalDOMEvent:DomEventcarrieskind,key/ch,mouseortext, plusprevent_default()andset_codemirror_ignore().Editor::signal_dom_event(&e, override)returnsdefaultPrevented || codemirrorIgnore, andEditor::on_dom_event(kind, f)registers a handler. It is wired where CM5 calls it:key_down: key_events.js:111. It runs beforedisplay.shiftis set, as in CM5.key_press: key_events.js:154.mouse_down: mouse_events.js:61. This is a 7-line insertion at the top of the function.paste: TextareaInput.js:50.scrollCursorIntoView: scrolling.js:16. When vetoed, the adapter gets no window rect. The editor's own scroll still happens.Upstream refs (pinned 4ca3d05)
src/util/event.js:11-56; src/edit/key_events.js:111,154; src/edit/mouse_events.js:61; src/input/TextareaInput.js:50; src/display/scrolling.js:16.
Tests and evidence
crates/cm-view/tests/named_events.rshas 8 tests:The existing typed-event suites pass unchanged.
Strict suite, before integration: 790 passed, 0 failed, both normally and under xvfb. Without xvfb, the first run had 1 failure, the known
app_scriptflake; the rerun was clean.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.Known differences
signal_dom_eventitself.scrollCursorIntoViewrun inside the display phase, as in CM5's endOperation. They should only callprevent_default.Coverage change
CI: pending (Actions cannot start: billing)