Skip to content

Commit

Permalink
Do not handle ENTER key when CTRL is pressed (#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Oct 24, 2024
1 parent 64ba856 commit e02c69a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class EditPlugin implements EditorPlugin {

private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {
const rawEvent = event.rawEvent;
const hasCtrlOrMetaKey = rawEvent.ctrlKey || rawEvent.metaKey;

if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
switch (rawEvent.key) {
Expand All @@ -169,7 +170,7 @@ export class EditPlugin implements EditorPlugin {
break;

case 'Tab':
if (this.options.handleTabKey) {
if (this.options.handleTabKey && !hasCtrlOrMetaKey) {
keyboardTab(editor, rawEvent);
}
break;
Expand All @@ -180,7 +181,9 @@ export class EditPlugin implements EditorPlugin {
break;

case 'Enter':
keyboardEnter(editor, rawEvent, this.handleNormalEnter);
if (!hasCtrlOrMetaKey) {
keyboardEnter(editor, rawEvent, this.handleNormalEnter);
}
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ describe('EditPlugin', () => {
expect(keyboardTabSpy).not.toHaveBeenCalled();
});

it('Ctrl+Enter, nothing happens', () => {
plugin = new EditPlugin();
const rawEvent = { which: 13, key: 'Enter', ctrlKey: true } as any;
const addUndoSnapshotSpy = jasmine.createSpy('addUndoSnapshot');

editor.takeSnapshot = addUndoSnapshotSpy;

plugin.initialize(editor);

plugin.onPluginEvent({
eventType: 'keyDown',
rawEvent,
});

expect(keyboardDeleteSpy).not.toHaveBeenCalled();
expect(keyboardInputSpy).not.toHaveBeenCalled();
expect(keyboardEnterSpy).not.toHaveBeenCalled();
expect(keyboardTabSpy).not.toHaveBeenCalled();
});

it('Other key', () => {
plugin = new EditPlugin();
const rawEvent = { which: 41, key: 'A' } as any;
Expand Down

0 comments on commit e02c69a

Please sign in to comment.