1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

flex copy directive

This commit is contained in:
Kyle Spearrin 2019-01-23 16:22:38 -05:00
parent 6dc44c0885
commit 09df62db4c

View File

@ -0,0 +1,28 @@
import {
Directive,
ElementRef,
HostListener,
} from '@angular/core';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
@Directive({
selector: '[appFlexCopy]',
})
export class FlexCopyDirective {
constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) { }
@HostListener('copy') onCopy() {
if (window == null) {
return;
}
let copyText = '';
const selection = window.getSelection();
for (let i = 0; i < selection.rangeCount; i++) {
const range = selection.getRangeAt(i);
const text = range.toString();
copyText += text;
}
this.platformUtilsService.copyToClipboard(copyText, { window: window });
}
}