Skip to content

Commit

Permalink
feat: support drop event (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ym authored and scttcper committed Oct 13, 2019
1 parent 7b861c9 commit 7d26916
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ All outputs of [ngModel](https://angular.io/api/forms/NgModel#outputs) and
* `focusChange` - called when the editor is focused or loses focus
* `scroll` - called when the editor is scrolled (not wrapped inside angular change detection must manually trigger change detection or run inside ngzone)
* `cursorActivity` - called when the text cursor is moved
* `drop` - called when file(s) are dropped

## License
MIT
Expand Down
11 changes: 11 additions & 0 deletions src/lib/codemirror.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class CodemirrorComponent
@Output() focusChange = new EventEmitter<boolean>();
/* called when the editor is scrolled */
@Output() scroll = new EventEmitter<ScrollInfo>();
/* called when file(s) are dropped */
@Output() drop = new EventEmitter<[Editor, DragEvent]>();
@ViewChild('ref', { static: true }) ref: ElementRef;
value = '';
disabled = false;
Expand Down Expand Up @@ -133,6 +135,12 @@ export class CodemirrorComponent
(cm: Editor, change: EditorChangeLinkedList) =>
this._ngZone.run(() => this.codemirrorValueChanged(cm, change)),
);
this.codeMirror.on(
'drop',
(cm: Editor, e: DragEvent) => {
this._ngZone.run(() => this.dropFiles(cm, e));
}
)
this.codeMirror.setValue(this.value);
});
}
Expand Down Expand Up @@ -186,6 +194,9 @@ export class CodemirrorComponent
cursorActive(cm: Editor) {
this.cursorActivity.emit(cm);
}
dropFiles(cm: Editor, e: DragEvent) {
this.drop.emit([cm, e]);
}
/** Implemented as part of ControlValueAccessor. */
writeValue(value: string): void {
if (value === null || value === undefined) {
Expand Down

0 comments on commit 7d26916

Please sign in to comment.