Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TypeError: Cannot read property 'type' of undefined" when deleting cells while cursor is over resizable column border #141

Open
ascott18 opened this issue Apr 20, 2021 · 2 comments

Comments

@ascott18
Copy link

ascott18 commented Apr 20, 2021

  1. With column resizing enabled, highlight two or more cells.
  2. Without releasing your left mouse button and while your cursor is close enough to a column border to trigger a resize cursor, press the Delete key to delete the cells.
  3. Observe the following error:
Uncaught (in promise) TypeError: Cannot read property 'type' of undefined
    at computeMap (index.es.js:273)
    at Function.get (index.es.js:268)
    at handleDecorations (index.es.js:3074)
    at Plugin.decorations (index.es.js:2811)
    at eval (index.es.js:6526)
    at EditorView.someProp (index.es.js:6806)
    at viewDecorations (index.es.js:6525)
    at EditorView.updateStateInner (index.es.js:6682)
    at EditorView.updateState (index.es.js:6652)
    at Editor.dispatchTransaction (tiptap.esm.js:1176)

This is because pluginState.activeHandle is not being cleared/reset to -1 when its corresponding node is removed. Also because handleDecorations in columnresizing.js is not checking that table is not null/undefined before passing it to TableMap.get(table).

In action:
988d2fa5-c4df-441c-b7f0-e0dcdf16b4fc

@ianmcateer
Copy link
Contributor

any possibility of this getting fixed? occurring for me as well when hovering over the resize cursor and undo'ing the history by pressing ctrl + z

@ianmcateer
Copy link
Contributor

ianmcateer commented May 17, 2022

the fix is here, just added a check for !table

function handleDecorations(state, cell) {
  let decorations = [];
  let $cell = state.doc.resolve(cell);
  let table = $cell.node(-1);
  if (!table) {
    return DecorationSet.empty;
  }
  let map = TableMap.get(table);

  let start = $cell.start(-1);
  let col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan;
  for (let row = 0; row < map.height; row++) {
    let index = col + row * map.width - 1;
    // For positions that are have either a different cell or the end
    // of the table to their right, and either the top of the table or
    // a different cell above them, add a decoration
    if (
      (col == map.width || map.map[index] != map.map[index + 1]) &&
      (row == 0 || map.map[index - 1] != map.map[index - 1 - map.width])
    ) {
      let cellPos = map.map[index];
      let pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
      let dom = document.createElement("div");
      dom.className = "column-resize-handle";
      decorations.push(Decoration.widget(pos, dom));
    }
  }
  return DecorationSet.create(state.doc, decorations);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants