Skip to content

Commit

Permalink
feat(client): add create-append-anything shortcuts
Browse files Browse the repository at this point in the history
Closes #3472
  • Loading branch information
smbea committed Feb 27, 2023
1 parent 0a385bb commit 1618a60
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 2 deletions.
30 changes: 30 additions & 0 deletions client/src/app/KeyboardBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ export default class KeyboardBindings {
action = getAction(this.replaceElement);
}

// create
if (isCreate(event) && isEnabled(this.createElement)) {
action = getAction(this.createElement);
}

// append
if (isAppend(event) && isEnabled(this.appendElement)) {
action = getAction(this.appendElement);
}

// custom
if (this.hasCustomEntry(event)) {
action = this.getCustomAction(event, 'keydown');
Expand Down Expand Up @@ -206,6 +216,8 @@ export default class KeyboardBindings {
this.undo = findUndo(menu);
this.redo = findRedo(menu);
this.replaceElement = findReplaceElement(menu);
this.createElement = findCreateElement(menu);
this.appendElement = findAppendElement(menu);
this.updateCustomEntries(menu);

return menu;
Expand Down Expand Up @@ -303,6 +315,16 @@ function isReplace(event) {
return isKey([ 'r', 'R' ], event) && !isCommandOrControl(event) && !isShift(event);
}

// n
function isCreate(event) {
return isKey([ 'n', 'N' ], event) && !isCommandOrControl(event) && !isShift(event);
}

// a
function isAppend(event) {
return isKey([ 'a', 'A' ], event) && !isCommandOrControl(event) && !isShift(event);
}

// Secondary delete shortcut
// Delete (Mac), Backspace (Linux, Windows)
function isSecondaryRemoveSelection(event, isMac) {
Expand Down Expand Up @@ -440,6 +462,14 @@ function findReplaceElement(menu) {
return find(menu, ({ accelerator }) => isAccelerator(accelerator, 'R'));
}

function findCreateElement(menu) {
return find(menu, ({ accelerator }) => isAccelerator(accelerator, 'N'));
}

function findAppendElement(menu) {
return find(menu, ({ accelerator }) => isAccelerator(accelerator, 'A'));
}

/**
* Check wether entry is enabled. If not specified it is enabled.
*
Expand Down
80 changes: 79 additions & 1 deletion client/src/app/__tests__/KeyboardBindingsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ describe('KeyboardBindings', function() {

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

});


Expand All @@ -379,7 +378,86 @@ describe('KeyboardBindings', function() {

// then
expect(actionSpy).to.not.have.been.called;
});

});


describe('createElement', function() {

it('should trigger for N', function() {

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

keyboardBindings.update([ {
accelerator: 'N',
action: 'createElement'
} ]);

// when
keyboardBindings._keyDownHandler(event);

// then
expect(actionSpy).to.have.been.calledWith('createElement');
});


it('should not trigger for Cmd+N', function() {

// given
event = createKeyEvent('N', { ctrlKey: true });

keyboardBindings.update([ {
accelerator: 'N',
action: 'createElement'
} ]);

// when
keyboardBindings._keyDownHandler(event);

// then
expect(actionSpy).to.not.have.been.called;
});

});


describe('appendElement', function() {

it('should trigger for N', function() {

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

keyboardBindings.update([ {
accelerator: 'A',
action: 'appendElement'
} ]);

// when
keyboardBindings._keyDownHandler(event);

// then
expect(actionSpy).to.have.been.calledWith('appendElement');
});


it('should not trigger for Cmd+A', function() {

// given
event = createKeyEvent('A', { ctrlKey: true });

keyboardBindings.update([ {
accelerator: 'A',
action: 'appendElement'
} ]);

// when
keyboardBindings._keyDownHandler(event);

// then
expect(actionSpy).to.not.have.been.called;
});

});
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,11 @@ export class BpmnEditor extends CachedComponent {

const newState = {
align: selectionLength > 1,
appendElement: !inputActive,
close: true,
copy: !!selectionLength,
cut: false,
createElement: !inputActive,
defaultCopyCutPaste: inputActive,
defaultUndoRedo: inputActive,
dirty,
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/tabs/cloud-bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,11 @@ export class BpmnEditor extends CachedComponent {

const newState = {
align: selectionLength > 1,
appendElement: !inputActive,
close: true,
copy: !!selectionLength,
cut: false,
createElement: !inputActive,
defaultCopyCutPaste: inputActive,
defaultUndoRedo: inputActive,
dirty,
Expand Down
24 changes: 23 additions & 1 deletion client/src/app/tabs/getEditMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ export function getSelectionEntries({
inputActive,
removeSelected,
selectAll,
replaceElement
replaceElement,
createElement,
appendElement

}) {
const menuEntries = [];
Expand All @@ -256,6 +258,26 @@ export function getSelectionEntries({
});
}

if (isDefined(appendElement)) {
menuEntries.push({
label: 'Append Element',
accelerator: 'A',
enabled: appendElement,
action: 'appendElement'
});
}

if (isDefined(createElement)) {
menuEntries.push({
label: 'Create Element',
accelerator: 'N',
enabled: createElement,
action: 'createElement',
options: {
opt: 'bpmn:Task'
}
});
}

if (isDefined(replaceElement)) {
menuEntries.push({
Expand Down

0 comments on commit 1618a60

Please sign in to comment.