fix: bypass CodeMirror posAtCoords for accurate cursor at non-100% CSS zoom
CSS zoom on document.documentElement causes a coordinate space mismatch between mouse event clientX/Y (viewport space) and Range.getClientRects() (CSS space), breaking CodeMirror's click-to-position mapping. The previous requestMeasure() fix only recalibrated cached geometry, not this mismatch. New approach: zoomCursorFix extension patches posAtCoords/posAndSideAtCoords on the EditorView instance to use document.caretRangeFromPoint() — the browser's native, zoom-aware API — with coord-adjustment fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,4 +66,14 @@ describe('useCodeMirror', () => {
|
||||
expect(spy).not.toHaveBeenCalled()
|
||||
spy.mockRestore()
|
||||
})
|
||||
|
||||
it('installs zoomCursorFix that overrides posAtCoords on the view instance', () => {
|
||||
const ref = { current: container }
|
||||
const { result } = renderHook(() =>
|
||||
useCodeMirror(ref, 'hello world', false, noopCallbacks),
|
||||
)
|
||||
const view = result.current.current!
|
||||
// The extension overrides posAtCoords on the instance (not the prototype)
|
||||
expect(Object.prototype.hasOwnProperty.call(view, 'posAtCoords')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user