Skip to content

Commit

Permalink
feat(client): add replace menu shortcut
Browse files Browse the repository at this point in the history
Closes #3332
  • Loading branch information
smbea committed Jan 2, 2023
1 parent b45aef6 commit c5533ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/src/app/KeyboardBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class KeyboardBindings {
this.paste = null;
this.selectAll = null;
this.removeSelection = null;
this.replaceElement = null;
this.undo = null;
this.redo = null;

Expand Down Expand Up @@ -136,6 +137,11 @@ export default class KeyboardBindings {
action = getAction(this.redo);
}

// replace
if (isKey([ 'r', 'R' ], event) && isEnabled(this.replaceElement)) {
action = getAction(this.replaceElement);
}

// custom
if (this.hasCustomEntry(event)) {
action = this.getCustomAction(event, 'keydown');
Expand Down Expand Up @@ -199,7 +205,7 @@ export default class KeyboardBindings {
this.selectAll = findSelectAll(menu);
this.undo = findUndo(menu);
this.redo = findRedo(menu);

this.replaceElement = findReplaceElement(menu);
this.updateCustomEntries(menu);

return menu;
Expand Down Expand Up @@ -425,6 +431,10 @@ function findSelectAll(menu) {
return find(menu, ({ accelerator }) => isAccelerator(accelerator, 'CommandOrControl+A'));
}

function findReplaceElement(menu) {
return find(menu, ({ accelerator }) => isAccelerator(accelerator, 'R'));
}

/**
* Check wether entry is enabled. If not specified it is enabled.
*
Expand Down
19 changes: 19 additions & 0 deletions client/src/app/__tests__/KeyboardBindingsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,25 @@ describe('KeyboardBindings', function() {
});


it('replaceElement', function() {

// given
event = createKeyEvent('R');

keyboardBindings.update([ {
accelerator: 'R',
action: 'replaceElement'
} ]);

// when
keyboardBindings._keyDownHandler(event);

// then
expect(actionSpy).to.have.been.calledWith(null, 'replaceElement');

});


it('#setOnAction', function() {

// given
Expand Down

0 comments on commit c5533ed

Please sign in to comment.