Workaround private editorContext. Add handler for delete key press

This commit is contained in:
BoykoAlex
2019-12-05 21:18:23 -05:00
parent d971d69a46
commit 48bf3ab42b
3 changed files with 24 additions and 13 deletions

View File

@@ -20,7 +20,7 @@
[resizerRight]="'#paper-container'">
</div>
<flo-editor-paper tabindex="0" (onDelete)="editorContext.deleteSelectedNode()"
<flo-editor-paper tabindex="0" (onDelete)="deleteSelected()"
(onProperties)="onPropertiesHandle()">
<div id="paper" class="paper" tabindex="0" style="overflow: hidden; position: absolute; display: block; height:100%; width:100%; overflow:auto;"></div>
<ng-content select="[canvas]"></ng-content>

View File

@@ -288,13 +288,11 @@ export class EditorComponent implements OnInit, OnDestroy {
}
deleteSelectedNode(): void {
if (self.selection) {
self.graph.trigger('startDeletion', self.selection.model);
}
self.deleteSelected();
}
delete(cell: dia.Cell) {
self.graph.trigger('startDeletion', cell);
self.delete(cell);
}
get textToGraphConversionObservable(): Observable<void> {
@@ -346,16 +344,16 @@ export class EditorComponent implements OnInit, OnDestroy {
this._disposables.dispose();
}
private delete(cell: dia.Cell) {
if (this.editor && this.editor.preDelete) {
if (this.editor.preDelete(this.editorContext, this.selection.model)) {
cell.remove();
}
} else {
cell.remove();
deleteSelected() {
if (this.selection) {
this.delete(this.selection.model);
}
}
delete(cell: dia.Cell) {
this.graph.trigger('startDeletion', cell);
}
get noPalette(): boolean {
return this._hiddenPalette;
}
@@ -1164,7 +1162,15 @@ export class EditorComponent implements OnInit, OnDestroy {
// adjust vertices when a cell is removed or its source/target was changed
this.graph.on('add remove change:source change:target change:vertices change:position', _.partial(Utils.fanRoute, this.graph));
this.graph.on('startDeletion', (cell: dia.Cell) => this.delete(cell));
this.graph.on('startDeletion', (cell: dia.Cell) => {
if (this.editor && this.editor.preDelete) {
if (this.editor.preDelete(this.editorContext, this.selection.model)) {
cell.remove();
}
} else {
cell.remove();
}
});
}
initPaperListeners() {

View File

@@ -41,6 +41,11 @@ export class PaperComponent {
this.onDelete.emit();
}
@HostListener('keydown.delete')
deleteHandle() {
this.onDelete.emit();
}
@HostListener('keydown.o')
oHandle() {
this.onProperties.emit();