diff --git a/src/cursor.ts b/src/cursor.ts index ffe191e..d84ad16 100644 --- a/src/cursor.ts +++ b/src/cursor.ts @@ -4,7 +4,7 @@ import {EditorView} from "./editorview" import {BlockType} from "./decoration" import {LineView} from "./blockview" import {atomicRanges} from "./extension" -import {clientRectsFor, textRange, Rect} from "./dom" +import {clientRectsFor, textRange, Rect, maxOffset} from "./dom" import {moveVisually, movedOver, Direction} from "./bidi" import {BlockInfo} from "./heightmap" import browser from "./browser" @@ -184,6 +184,10 @@ export function posAtCoords(view: EditorView, coords: {x: number, y: number}, pr node = undefined } } + // Chrome will return offsets into elements without child + // nodes, which will lead to a null deref below, so clip the + // offset to the node size. + if (node) offset = Math.min(maxOffset(node), offset) } // No luck, do our own (potentially expensive) search