mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
flex copy directive
This commit is contained in:
parent
6dc44c0885
commit
09df62db4c
28
src/angular/directives/flex-copy.directive.ts
Normal file
28
src/angular/directives/flex-copy.directive.ts
Normal 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 });
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user