Skip to content

Commit

Permalink
feat(create-append-anything): add create shortcut
Browse files Browse the repository at this point in the history
Trigger create with 'n' and 'a' if no selection

Closes #1814
  • Loading branch information
smbea committed Jan 24, 2023
1 parent 4e162ac commit 72fec1a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/features/create-append-anything/CreateAppendEditorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CreateAppendEditorActions.prototype.registerActions = function() {
var editorActions = this._injector.get('editorActions', false);
var selection = this._injector.get('selection', false);
var contextPad = this._injector.get('contextPad', false);
var palette = this._injector.get('palette', false);

const actions = {};

Expand All @@ -36,6 +37,15 @@ CreateAppendEditorActions.prototype.registerActions = function() {
);
}

// create
if (palette) {
assign(actions, {
'createElement': function(event) {
palette.triggerEntry('create', 'click', event);
} }
);
}

editorActions && editorActions.register(actions);

};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function CreateAppendKeyboardBindings(injector) {
this._injector = injector;
this._keyboard = this._injector.get('keyboard', false);
this._editorActions = this._injector.get('editorActions', false);
this._selection = this._injector.get('selection', false);

if (this._keyboard) {
this._injector.invoke(KeyboardBindings, this);
Expand All @@ -36,6 +37,7 @@ CreateAppendKeyboardBindings.prototype.registerBindings = function() {

var keyboard = this._keyboard;
var editorActions = this._editorActions;
var selection = this._selection;

// inherit default bindings
KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
Expand All @@ -54,7 +56,7 @@ CreateAppendKeyboardBindings.prototype.registerBindings = function() {
}
}

// activate append element
// activate append/create element
// A
addListener('appendElement', function(context) {

Expand All @@ -65,7 +67,28 @@ CreateAppendKeyboardBindings.prototype.registerBindings = function() {
}

if (keyboard && keyboard.isKey([ 'a', 'A' ], event)) {
editorActions && editorActions.trigger('appendElement', event);

if (selection && selection.get().length == 1) {
editorActions && editorActions.trigger('appendElement', event);
} else {
editorActions && editorActions.trigger('createElement', event);
}

return true;
}
});

// N
addListener('createElement', function(context) {

var event = context.keyEvent;

if (keyboard && keyboard.hasModifier(event)) {
return;
}

if (keyboard && keyboard.isKey([ 'n', 'N' ], event)) {
editorActions && editorActions.trigger('createElement', event);

return true;
}
Expand Down
1 change: 1 addition & 0 deletions test/spec/ModelerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe('Modeler', function() {
// given
var expectedActions = [
'appendElement',
'createElement',
'undo',
'redo',
'copy',
Expand Down

0 comments on commit 72fec1a

Please sign in to comment.