File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,29 @@ it('should replace selected content with the tab', () => {
6161 expect ( toPlainText ( before ) ) . toEqual ( initialText ) ;
6262 expect ( toPlainText ( after ) ) . toEqual ( tabs ( 1 ) ) ;
6363} ) ;
64+
65+ it ( 'should match the indentation of the previous line' , ( ) => {
66+ const evt = { preventDefault : jest . fn ( ) } ;
67+ const initialText = `${ tabs ( 2 ) } const a = 'b';\n` ;
68+
69+ const currentContent = ContentState . createFromText ( initialText ) ;
70+ // " const a = 'b'
71+ // "
72+ // ^ cursor here (on second line/in second block)
73+ const cursorOnSecondLine = SelectionState . createEmpty (
74+ currentContent
75+ . getBlockMap ( )
76+ . last ( )
77+ . getKey ( )
78+ ) ;
79+ const before = EditorState . create ( {
80+ allowUndo : true ,
81+ currentContent,
82+ // Focus the entire initial word
83+ selection : cursorOnSecondLine
84+ } ) ;
85+
86+ const after = handleTab ( evt , before ) ;
87+ expect ( toPlainText ( before ) ) . toEqual ( initialText ) ;
88+ expect ( toPlainText ( after ) ) . toEqual ( initialText + tabs ( 2 ) ) ;
89+ } ) ;
You can’t perform that action at this time.
0 commit comments