Repository navigation
Options by name: setOption/getOption, optionChange, defineOption, init hooks, autofocus, phrase (Refs #41) - #90
DJAscendance wants to merge 10 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.
…t hooks, autofocus, phrase (Refs #41) set_option/get_option map CM5 option names onto EditorOptions, run each option's handler in an operation (mode, indentUnit, tabSize, lineWrapping, the gutter options, resetModeState options, undoDepth, viewportMargin) and fire optionChange. define_option adds custom options with handlers run on init (CodeMirror.Init) unless notOnInit; the constructor ends with finishInit, the defineInitHook hooks and autofocus's 20 ms onFocus timer. line_number_for applies lineNumberFormatter; phrase reads the phrases option. Stacked on feat/focus-blink (run_timers).
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).
… uses lineNumberFor Keep both sides' options fields, listeners and README sections. The native renderer, cm-web's frame and the line-number width now format numbers through line_number_for (lineNumberFor: lineNumberFormatter(i + firstLineNumber), without subtracting doc.first, as update_line.js:114 and line_numbers.js:34 do). Render number buffers are keyed by text. New test line_number_formatter_sizes_gutter.
MiniMax-M3.1-Flash QAReview findings1.
|
Refs #41
Ledger rows: 82 lineNumberFor, 341 CodeMirror constructor, 436 setOption (with getOption), 482 phrase, 514 defineOptions.
Base:
7d917785a1b65259b238f35a3fad98343d8a6d02(master, merged in); parent PR head941d6c6cfcf4eebc4b4d0e36a9386def958def99Head:
ac0238af964e2cfd1d36b7568b2227dcd86f3a3cIntegration: Stacked on #89 (
941d6c6); 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
The new module is
crates/cm-view/src/options.rs.OptionValuecovers Null, Bool, Number, Str, Phrases and Formatter.OldValueisInitorValue.Editor::get_option(name)returnsNonefor an unknown name (CM5's undefined).Editor::set_option(name, value), as in methods.js:43:mode.doc.modeOption+ loadMode;optionChange(Editor::on_option_change, immediate).OptionError.options::define_option(name, default, handler, not_on_init)is CodeMirror.defineOption for custom options. Their handlers run on a new editor withOldValue::Init, unlessnot_on_init. Built-in names are refused, because built-in options are typed fields.options::BUILT_INlists the implemented option names, andoptions::default_option(name)gives CodeMirror.defaults.EditorOptions::finish_init, then theoptions::define_init_hookhooks. WithEditorOptions::autofocus, a 20 ms timeout runs onFocus unless the editor is already focused. In CM5 the focus listener is registered afterinput.focus(), so that timeout is what focuses the editor.Editor::line_number_for(i)returnslineNumberFormatter(i + firstLineNumber), usingEditorOptions::line_number_formatter.Editor::phrase(text)reads thephrasesoption (EditorOptions::phrases).Upstream refs (pinned 4ca3d05)
src/edit/options.js:24-183; src/edit/methods.js:43-52, 437-440; src/edit/CodeMirror.js:63-90, 216-217; src/line/utils_line.js:83.
Tests and evidence
crates/cm-view/tests/options.rs:set_get_and_option_change: the tabSize handler changes the layout, unchanged values are a no-op, mode always runs, and errors are returned.line_number_for_and_gutter_optionsphrasesdefine_option_custom: Init versus notOnInit, old values, defaults, and the built-in refusal.finish_init_and_init_hooks: finishInit runs before the hooks.autofocus_focuses_after_20ms0b167ad, 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
line_number_for.)"nocursor", the lineSeparator handler (re-splitting the document) and keyMap attach/detach are not ported.Coverage change
After the merge, the native renderer, cm-web's frame and the gutter width all format numbers through
line_number_for(row 82).lineNumberForuses the absolute line number and does not subtractdoc.first, as CM5 does. New test:line_number_formatter_sizes_gutter.CI: pending (Actions cannot start: billing)