-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathcellselection-rect.test.ts
More file actions
89 lines (73 loc) · 2.34 KB
/
cellselection-rect.test.ts
File metadata and controls
89 lines (73 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import ist from 'ist';
import { describe, it } from 'vitest';
import { TableMap } from '../src';
import { table, tr, td, p } from './build';
describe('CellSelection rectangular constraint', () => {
it('should expand selection to include full rowspan cells', () => {
// Table structure:
// | A | B (rowspan=2) | C |
// | D | B | E |
const tableNode = table(
tr(
td(p('A')), // pos 1
td({ rowspan: 2 }, p('B')), // pos 6
td(p('C')), // pos 11
),
tr(
td(p('D')), // pos 18
// B continues here
td(p('E')), // pos 23
),
);
const map = TableMap.get(tableNode);
// Select from A (pos=1) to C (pos=11)
// Because B has rowspan=2, the selection should expand to a rectangle
// that includes D and E
const rect = map.rectBetween(1, 11);
console.log('Map:', map.map);
console.log('Rect:', rect);
console.log('Cells in rect:', map.cellsInRect(rect));
// Expected: selection should include all cells A, B, C, D, E
const cells = map.cellsInRect(rect);
// Verify the selection is rectangular (should include the second row)
ist(rect.top, 0);
ist(rect.bottom, 2); // Should be 2, not 1
ist(rect.left, 0);
ist(rect.right, 3);
// Should include all 5 cells
ist(cells.length, 5);
});
it('should expand selection to include full colspan cells', () => {
// Table structure:
// | A | B | C |
// | D (colspan=2) | E |
// When selecting from A to E, crossing D (colspan=2),
// the selection should be a complete rectangle
const tableNode = table(
tr(
td(p('A')), // pos 1
td(p('B')), // pos 6
td(p('C')), // pos 11
),
tr(
td({ colspan: 2 }, p('D')), // pos 18
td(p('E')), // pos 23
),
);
const map = TableMap.get(tableNode);
// Select from A (pos=1) to E (pos=23)
// Should form a complete rectangle
const rect = map.rectBetween(1, 23);
console.log('Map:', map.map);
console.log('Rect:', rect);
console.log('Cells in rect:', map.cellsInRect(rect));
const cells = map.cellsInRect(rect);
// Verify the selection is rectangular
ist(rect.top, 0);
ist(rect.bottom, 2);
ist(rect.left, 0);
ist(rect.right, 3);
// Should include all cells
ist(cells.length, 5);
});
});