Skip to content

Commit

Permalink
wip feat(editor): add removeSelection action
Browse files Browse the repository at this point in the history
Related to #437
  • Loading branch information
Niklas Kiefer committed Nov 29, 2022
1 parent f30dbf7 commit 2b1064a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class FormEditorActions extends EditorActions {
_registerDefaultActions(injector) {
const commandStack = injector.get('commandStack', false),
formFieldRegistry = injector.get('formFieldRegistry', false),
modeling = injector.get('modeling', false),
selection = injector.get('selection', false);

if (commandStack) {
Expand Down Expand Up @@ -48,11 +49,45 @@ export default class FormEditorActions extends EditorActions {
selection.set(formField);
}
});

}

if (modeling && selection) {

// @ts-ignore
this.register('removeSelection', () => {
const selectedFormField = selection.get();

if (!selectedFormField) {
return;
}

const parentField = formFieldRegistry.get(selectedFormField._parent);

const index = getFormFieldIndex(parentField, selectedFormField);

modeling.removeFormField(selectedFormField, parentField, index);
});
}
}
}

FormEditorActions.$inject = [
'eventBus',
'injector'
];
];


// helper ////////////

function getFormFieldIndex(parent, formField) {
let fieldFormIndex = parent.components.length;

parent.components.forEach(({ id }, index) => {
if (id === formField.id) {
fieldFormIndex = index;
}
});

return fieldFormIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export default class FormEditorKeyboardBindings {
}
});

// delete selected field
// DEL
addListener('removeSelection', (context) => {

const { keyEvent } = context;

if (isKey([ 'Backspace', 'Delete', 'Del' ], keyEvent)) {

editorActions.trigger('removeSelection');

return true;
}
});
}
}

Expand Down

0 comments on commit 2b1064a

Please sign in to comment.