Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/__tests__/handle-tab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,29 @@ it('should replace selected content with the tab', () => {
expect(toPlainText(before)).toEqual(initialText);
expect(toPlainText(after)).toEqual(tabs(1));
});

it('should match the indentation of the previous line', () => {
const evt = { preventDefault: jest.fn() };
const initialText = `${tabs(2)}const a = 'b';\n`;

const currentContent = ContentState.createFromText(initialText);
// " const a = 'b'
// "
// ^ cursor here (on second line/in second block)
const cursorOnSecondLine = SelectionState.createEmpty(
currentContent
.getBlockMap()
.last()
.getKey()
);
const before = EditorState.create({
allowUndo: true,
currentContent,
// Focus the entire initial word
selection: cursorOnSecondLine
});

const after = handleTab(evt, before);
expect(toPlainText(before)).toEqual(initialText);
expect(toPlainText(after)).toEqual(initialText + tabs(2));
});