Skip to content

Commit

Permalink
Fix issue with 'Enter' key in circulation rules editor that adds inde…
Browse files Browse the repository at this point in the history
…nt to previous line
  • Loading branch information
artem-blazhko committed Feb 22, 2024
1 parent 3154e4b commit 6e44bdf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/settings/lib/RuleEditor/RulesEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
56 changes: 37 additions & 19 deletions src/settings/lib/RuleEditor/RulesEditor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Expand Down

0 comments on commit 6e44bdf

Please sign in to comment.