Skip to content

[WIP] Tab indentation completion #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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));
});