File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,36 @@ describe('table plugin', () => {
119119 . should ( 'have.length' , 3 )
120120 . each ( td => cy . wrap ( td ) . should ( 'have.css' , 'text-align' , 'center' ) )
121121 } )
122+
123+ it ( 'Creates table and add multilines' , function ( ) {
124+ const tag = 'table'
125+ const multilinesContent = 'Line 1\nLine 2\nLine 3'
126+
127+ const currentFolder = Cypress . currentTest . title
128+ cy . createFolder ( currentFolder )
129+
130+ cy . visit ( `apps/files?dir=/${ encodeURIComponent ( currentFolder ) } ` )
131+ cy . openWorkspace ( )
132+ . type ( 'Hello !' )
133+
134+ cy . getMenuEntry ( tag )
135+ . click ( )
136+ cy . should ( 'have.class' , 'is-active' )
137+
138+ cy . getContent ( )
139+ . find ( `${ tag } ` ) . should ( 'be.visible' )
140+
141+ cy . get ( '#rich-workspace .ProseMirror' )
142+ . get ( 'table:nth-of-type(1) tr:nth-child(2) td:nth-child(1)' )
143+ . click ( )
144+ cy . type ( multilinesContent )
145+
146+ cy . getEditor ( )
147+ . find ( 'table:nth-of-type(1) tr:nth-child(2) td:nth-child(1) .content' )
148+ . then ( ( $el ) => {
149+ expect ( $el . get ( 0 ) . innerHTML ) . to . equal ( multilinesContent . replace ( / \n / g, '<br>' ) )
150+ } )
151+ } )
122152} )
123153
124154describe ( 'Table extension integrated in the editor' , ( ) => {
Original file line number Diff line number Diff line change @@ -298,6 +298,7 @@ describe('Workspace', function() {
298298 checkContent ( )
299299 } )
300300 } )
301+
301302} )
302303
303304const openSidebar = filename => {
Original file line number Diff line number Diff line change 11import { TableCell } from '@tiptap/extension-table-cell'
2+ import { Plugin } from '@tiptap/pm/state'
3+ import { Fragment } from '@tiptap/pm/model'
24
35export default TableCell . extend ( {
46 content : 'inline*' ,
@@ -30,4 +32,35 @@ export default TableCell.extend({
3032 } ,
3133 }
3234 } ,
35+
36+ addProseMirrorPlugins ( ) {
37+ return [
38+ new Plugin ( {
39+ props : {
40+ // Special-treat empty lines in pasted content to prevent jumping out of cell
41+ handlePaste : ( view , event , slice ) => {
42+ if ( slice . content . childCount > 1 ) {
43+ const state = view . state
44+ const childCount = slice . content . childCount
45+ const childNodes = [ ]
46+ for ( let i = 0 ; i < childCount ; i ++ ) {
47+ if ( i === 0 ) {
48+ childNodes . push ( state . schema . text ( '\n' ) )
49+ }
50+
51+ // Ignore empty children (i.e. empty lines)
52+ if ( ! slice . content . child ( i ) . firstChild ) {
53+ continue
54+ }
55+
56+ childNodes . push ( state . schema . text ( slice . content . child ( i ) . textContent , slice . content . child ( i ) . firstChild . marks ) )
57+ }
58+ const newNode = view . state . schema . node ( 'paragraph' , [ ] , childNodes )
59+ slice . content = Fragment . empty . addToStart ( newNode )
60+ }
61+ } ,
62+ } ,
63+ } ) ,
64+ ]
65+ } ,
3366} )
You can’t perform that action at this time.
0 commit comments