outline / rich-markdown-editor

The open source React and Prosemirror based markdown editor that powers Outline. Want to try it out? Create an account:
https://www.getoutline.com
BSD 3-Clause "New" or "Revised" License
2.87k stars 592 forks source link

Throw exception "Error: Invalid position 0" if select all text in line by shift+home and press "/" #443

Closed RuslanGabbasov closed 3 years ago

RuslanGabbasov commented 3 years ago

To Reproduce Steps to reproduce the behavior:

  1. Write anything
  2. Select by mouse or by shift+home text to start of line
  3. Press "/"
  4. See error:

    
    domFromPos
    src/viewdesc.js:279
    
    276 |   node: this.contentDOM,
    277 |   offset: child ? domIndex(child.dom) : this.contentDOM.childNodes.length
    278 | }
    > 279 | if (!child) throw new Error("Invalid position " + pos)
      | ^  280 | let end = offset + child.size
    281 | if (!child.domAtom && (side < 0 && !child.border ? end >= pos : end > pos) &&
    282 |     (end > pos || i + 1 >= this.children.length || !this.children[i + 1].beforePosition))

domFromPos src/viewdesc.js:283

280 | let end = offset + child.size 281 | if (!child.domAtom && (side < 0 && !child.border ? end >= pos : end > pos) && 282 | (end > pos || i + 1 >= this.children.length || !this.children[i + 1].beforePosition))

283 | return child.domFromPos(pos - offset - child.border, side) | ^ 284 | offset = end 285 | } 286 | }

coordsAtPos src/domcoords.js:297

294 | // Given a position in the document model, get a bounding box of the 295 | // character at that position, relative to the window. 296 | export function coordsAtPos(view, pos, side) {

297 | let {node, offset} = view.docView.domFromPos(pos, side < 0 ? -1 : 1) 298 | 299 | let supportEmptyRange = browser.webkit || browser.gecko 300 | if (node.nodeType == 3) {

coordsAtPos$1 src/index.js:286

283 | 284 | // Reset variableStore 285 | variableStore.dom = {};

286 | } | ^ 287 | } 288 | } 289 | }

usePosition src/components/FloatingToolbar.tsx:59

56 | const { view, active } = props; 57 | const { selection } = view.state; 58 | const { width: menuWidth, height: menuHeight } = useComponentSize(menuRef);

59 | if (!active || !menuWidth || !menuHeight || SSR || isSelectingText) { | ^ 60 | return defaultPosition; 61 | } 62 | const fromPos = view.coordsAtPos(selection.$from.pos);

Version <= 11.8.0

tommoor commented 3 years ago

I cannot reproduce but I absolutely believe this can happen, my keyboard also does not have the home key either.

Are you able to provide a video?

RuslanGabbasov commented 3 years ago

07 05 2021 18 23 35

RuslanGabbasov commented 3 years ago

Thanks a lot!