diff --git a/src/settings/lib/RuleEditor/RulesEditor.js b/src/settings/lib/RuleEditor/RulesEditor.js index 5b2f92ed..d0a86b5f 100644 --- a/src/settings/lib/RuleEditor/RulesEditor.js +++ b/src/settings/lib/RuleEditor/RulesEditor.js @@ -86,7 +86,10 @@ export function handleEnter(cm, handle) { return; } - cm.execCommand('newlineAndIndent'); + const activeDocument = cm.getDoc(); + const cursor = activeDocument.getCursor(); + + activeDocument.replaceRange('\n', cursor); } export function selectHint(cm, handle) { diff --git a/src/settings/lib/RuleEditor/RulesEditor.test.js b/src/settings/lib/RuleEditor/RulesEditor.test.js index ebf0f045..049ef9af 100644 --- a/src/settings/lib/RuleEditor/RulesEditor.test.js +++ b/src/settings/lib/RuleEditor/RulesEditor.test.js @@ -152,30 +152,48 @@ describe('RulesEditor', () => { }); describe('when "selectHint" does not return true', () => { - it('should trigger "execCommand" with correct argument', () => { - const execCommand = jest.fn(); - const codeMirror = { - execCommand, - state: { - completionActive: { - widget: { - currentSectionIndex: 0, - }, + const cursor = { + line: '', + }; + const getCursor = jest.fn(() => cursor); + const replaceRange = jest.fn(); + const codeMirror = { + getDoc: jest.fn(() => ({ + getCursor, + replaceRange, + })), + state: { + completionActive: { + widget: { + currentSectionIndex: 0, }, }, - }; - const handle = { - data: { - sections: [{ - selectedHintIndex: -1, - }], - }, - }; - const expectedArg = 'newlineAndIndent'; + }, + }; + const handle = { + data: { + sections: [{ + selectedHintIndex: -1, + }], + }, + }; + beforeEach(() => { handleEnter(codeMirror, handle); + }); + + it('should get document information', () => { + expect(codeMirror.getDoc).toHaveBeenCalled(); + }); - expect(execCommand).toHaveBeenCalledWith(expectedArg); + it('should get cursor information', () => { + expect(getCursor).toHaveBeenCalled(); + }); + + it('should change cursor position', () => { + const expectedArgs = ['\n', cursor]; + + expect(replaceRange).toHaveBeenCalledWith(...expectedArgs); }); }); });