Repository navigation
Cursor drawing: showCursorWhenSelecting, cursorHeight, fat cursor, overwriteToggle (Refs #51) - #92
DJAscendance wants to merge 14 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).
swap_doc detaches the old document, attaches the new one, keeps each document's scroll position, loads doc.modeOption, resets the highlight state, line heights and longest line, scrolls to the new document's position and fires swapDoc delayed. refresh() is the methodOp of methods.js:411 with the immediate refresh event; set_metrics runs it. on_resize applies re-measured metrics and setSize. Doc gains set_mode_option, scroll_pos and set_scroll_pos; the editor writes doc.modeOption when the mode is set.
…erwriteToggle (Refs #51) Editor::cursor_rects is prepareSelection/drawSelectionCursor's cursor geometry: cursors for empty ranges or every range with showCursorWhenSelecting, among ranges reaching [viewFrom, viewTo), with cursorHeight scaling and the cm-fat-cursor width (charCoords width or defaultCharWidth). The renderer draws from it. toggleOverwrite fires overwriteToggle. Checked against a CM5 recording (oracle/cm5-cursors.mjs).
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.
Keep both listener sets. Use master's reg_change_all(first, size). swap_doc also recomputes has_widgets for the new document and carries addModeClass into the fresh highlight state. New test swap_doc_line_widget_heights.
…wing Keep both sides' options and listeners. cursor_rects uses CoordSys::Doc, the internal document frame after #81 (CM5's "div" plus viewOffset).
MiniMax-M3.1-Flash QAFindings[High] Newly added built-in options are not exposed through
|
Refs #51
Ledger rows: 469 toggleOverwrite, 671 prepareSelection, 672 drawSelectionCursor.
Base:
7d917785a1b65259b238f35a3fad98343d8a6d02(master, merged in); parent PR head5ee41bf7dfbe0684c885a175941224129bfe97adHead:
0b167ad942cf24b7f95e94d863f17a85bddfe080Integration: Stacked on #91 (
5ee41bf); 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
Editor::cursor_rects() -> Vec<(Pos, Rect)>. These are the cursorsprepareSelectiondraws, withdrawSelectionCursor's geometry:[viewFrom, viewTo). Empty ranges always get one; withshowCursorWhenSelecting, every range does.cursorCoords(head, "div")left/top.max(0, bottom - top) * cursorHeight.cm-fat-cursorclass,charCoordsright - left, ordefaultCharWidth()at the end of a line. Otherwise 0.EditorOptionsfields:show_cursor_when_selecting(default false),cursor_height(default 1) andfat_cursor(the wrapper class the vim keymap's normal mode sets).cursor_rects. A fat cursor takes its width, and the normal and overwrite cursor widths are unchanged.toggle_overwritefiresoverwriteToggle(Editor::on_overwrite_toggle, immediate) when the state changes.Upstream refs (pinned 4ca3d05)
src/display/selection.js:13-60; src/edit/methods.js:352-360; lib/codemirror.css:45-61.
Tests and evidence
oracle/cm5-cursors.mjsrecords 14 cases from CodeMirror 5.65.21 in headless Chromium intocrates/cm-view/tests/data/cm5-cursors.json. Page metrics:Metrics::oracle(), setSize(600, 300). The cases cover:crates/cm-view/tests/cursors.rs::cursors_match_cm5: every cursor's left, top, height and fat width match CM5 within 0.01 px.crates/cm-view/tests/cursors.rs::overwrite_toggle_event0b167ad, 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
pos.other).singleCursorHeightPerLine: falseis not modeled.$customCursorand theprimary = falsepath are not ported.Coverage change
After the merge,
cursor_rectsusesCoordSys::Doc, the internal frame after #81.CI: pending (Actions cannot start: billing)