Skip to content

Commit c233061

Browse files
committed
Add failing test for tab indentation completion
1 parent 2ff6789 commit c233061

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/__tests__/handle-tab.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
});

0 commit comments

Comments
 (0)