Skip to content

Commit

Permalink
handleDecorations to check whether table is undefined or null (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcateer authored Jul 11, 2022
1 parent 93778a8 commit 23c79ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/columnresizing.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,15 @@ function zeroes(n) {
return result;
}

function handleDecorations(state, cell) {
export function handleDecorations(state, cell) {
let decorations = [];
let $cell = state.doc.resolve(cell);
let table = $cell.node(-1),
map = TableMap.get(table),
start = $cell.start(-1);
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;
Expand Down
14 changes: 14 additions & 0 deletions test/test-column-resizing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ist from 'ist';
import { EditorState } from 'prosemirror-state';
import { DecorationSet } from 'prosemirror-view';
import { handleDecorations } from '../src/columnresizing';
import { table, doc, tr, cEmpty } from './build';

describe('handleDecorations', () => {
it('returns an empty DecorationSet if cell is null or undefined', () => {
let state = EditorState.create({
doc: doc(table(tr(/* 2*/ cEmpty, /* 6*/ cEmpty, /*10*/ cEmpty))),
});
ist(handleDecorations(state, null), DecorationSet.empty);
});
});

0 comments on commit 23c79ae

Please sign in to comment.