@@ -13,42 +13,35 @@ import {
13
13
const getEditor = setupTestEnv ( ) ;
14
14
15
15
function makeSelectionSpanContent ( selectionType : "text" | "node" | "cell" ) {
16
- const blockInfo = getBlockInfoFromSelection ( getEditor ( ) . _tiptapEditor . state ) ;
16
+ const blockInfo = getBlockInfoFromSelection ( getEditor ( ) . prosemirrorState ) ;
17
17
if ( ! blockInfo . isBlockContainer ) {
18
18
throw new Error (
19
19
`Selection points to a ${ blockInfo . blockNoteType } node, not a blockContainer node`
20
20
) ;
21
21
}
22
22
const { blockContent } = blockInfo ;
23
23
24
+ const editor = getEditor ( ) ;
25
+ const tr = editor . transaction ;
24
26
if ( selectionType === "cell" ) {
25
- getEditor ( ) . dispatch (
26
- getEditor ( ) . _tiptapEditor . state . tr . setSelection (
27
+ editor . dispatch (
28
+ tr . setSelection (
27
29
CellSelection . create (
28
- getEditor ( ) . _tiptapEditor . state . doc ,
29
- getEditor ( )
30
- . _tiptapEditor . state . doc . resolve ( blockContent . beforePos + 3 )
31
- . before ( ) ,
32
- getEditor ( )
33
- . _tiptapEditor . state . doc . resolve ( blockContent . afterPos - 3 )
34
- . before ( )
30
+ tr . doc ,
31
+ tr . doc . resolve ( blockContent . beforePos + 3 ) . before ( ) ,
32
+ tr . doc . resolve ( blockContent . afterPos - 3 ) . before ( )
35
33
)
36
34
)
37
35
) ;
38
36
} else if ( selectionType === "node" ) {
39
- getEditor ( ) . dispatch (
40
- getEditor ( ) . _tiptapEditor . state . tr . setSelection (
41
- NodeSelection . create (
42
- getEditor ( ) . _tiptapEditor . state . doc ,
43
- blockContent . beforePos
44
- )
45
- )
37
+ editor . dispatch (
38
+ tr . setSelection ( NodeSelection . create ( tr . doc , blockContent . beforePos ) )
46
39
) ;
47
40
} else {
48
- getEditor ( ) . dispatch (
49
- getEditor ( ) . _tiptapEditor . state . tr . setSelection (
41
+ editor . dispatch (
42
+ tr . setSelection (
50
43
TextSelection . create (
51
- getEditor ( ) . _tiptapEditor . state . doc ,
44
+ tr . doc ,
52
45
blockContent . beforePos + 1 ,
53
46
blockContent . afterPos - 1
54
47
)
@@ -64,13 +57,11 @@ describe("Test moveSelectedBlockAndSelection", () => {
64
57
65
58
moveSelectedBlocksAndSelection ( getEditor ( ) , "paragraph-0" , "before" ) ;
66
59
67
- const selection = getEditor ( ) . _tiptapEditor . state . selection ;
60
+ const selection = getEditor ( ) . transaction . selection ;
68
61
getEditor ( ) . setTextCursorPosition ( "paragraph-1" ) ;
69
62
makeSelectionSpanContent ( "text" ) ;
70
63
71
- expect (
72
- selection . eq ( getEditor ( ) . _tiptapEditor . state . selection )
73
- ) . toBeTruthy ( ) ;
64
+ expect ( selection . eq ( getEditor ( ) . transaction . selection ) ) . toBeTruthy ( ) ;
74
65
} ) ;
75
66
76
67
it ( "Node selection" , ( ) => {
@@ -79,13 +70,11 @@ describe("Test moveSelectedBlockAndSelection", () => {
79
70
80
71
moveSelectedBlocksAndSelection ( getEditor ( ) , "paragraph-0" , "before" ) ;
81
72
82
- const selection = getEditor ( ) . _tiptapEditor . state . selection ;
73
+ const selection = getEditor ( ) . transaction . selection ;
83
74
getEditor ( ) . setTextCursorPosition ( "image-0" ) ;
84
75
makeSelectionSpanContent ( "node" ) ;
85
76
86
- expect (
87
- selection . eq ( getEditor ( ) . _tiptapEditor . state . selection )
88
- ) . toBeTruthy ( ) ;
77
+ expect ( selection . eq ( getEditor ( ) . transaction . selection ) ) . toBeTruthy ( ) ;
89
78
} ) ;
90
79
91
80
it ( "Cell selection" , ( ) => {
@@ -94,39 +83,33 @@ describe("Test moveSelectedBlockAndSelection", () => {
94
83
95
84
moveSelectedBlocksAndSelection ( getEditor ( ) , "paragraph-0" , "before" ) ;
96
85
97
- const selection = getEditor ( ) . _tiptapEditor . state . selection ;
86
+ const selection = getEditor ( ) . transaction . selection ;
98
87
getEditor ( ) . setTextCursorPosition ( "table-0" ) ;
99
88
makeSelectionSpanContent ( "cell" ) ;
100
89
101
- expect (
102
- selection . eq ( getEditor ( ) . _tiptapEditor . state . selection )
103
- ) . toBeTruthy ( ) ;
90
+ expect ( selection . eq ( getEditor ( ) . transaction . selection ) ) . toBeTruthy ( ) ;
104
91
} ) ;
105
92
106
93
it ( "Multiple block selection" , ( ) => {
107
94
getEditor ( ) . setSelection ( "paragraph-1" , "paragraph-2" ) ;
108
95
109
96
moveSelectedBlocksAndSelection ( getEditor ( ) , "paragraph-0" , "before" ) ;
110
97
111
- const selection = getEditor ( ) . _tiptapEditor . state . selection ;
98
+ const selection = getEditor ( ) . transaction . selection ;
112
99
getEditor ( ) . setSelection ( "paragraph-1" , "paragraph-2" ) ;
113
100
114
- expect (
115
- selection . eq ( getEditor ( ) . _tiptapEditor . state . selection )
116
- ) . toBeTruthy ( ) ;
101
+ expect ( selection . eq ( getEditor ( ) . transaction . selection ) ) . toBeTruthy ( ) ;
117
102
} ) ;
118
103
119
104
it ( "Multiple block selection with table" , ( ) => {
120
105
getEditor ( ) . setSelection ( "paragraph-6" , "table-0" ) ;
121
106
122
107
moveSelectedBlocksAndSelection ( getEditor ( ) , "paragraph-0" , "before" ) ;
123
108
124
- const selection = getEditor ( ) . _tiptapEditor . state . selection ;
109
+ const selection = getEditor ( ) . transaction . selection ;
125
110
getEditor ( ) . setSelection ( "paragraph-6" , "table-0" ) ;
126
111
127
- expect (
128
- selection . eq ( getEditor ( ) . _tiptapEditor . state . selection )
129
- ) . toBeTruthy ( ) ;
112
+ expect ( selection . eq ( getEditor ( ) . transaction . selection ) ) . toBeTruthy ( ) ;
130
113
} ) ;
131
114
} ) ;
132
115
0 commit comments