My Clipboard service includes a copy()
and paste()
method that is triggered by Ctrl+C
and Ctrl+V
commands. These methods are document-level keyboard listeners added to a component using HostListeners. However, I am facing an issue where the paste()
method is triggered when the user tries to paste text, which is not the intended behavior. Can anyone provide guidance on how to prevent this from happening?
Below is my Clipboard Service:
export class ClipService {
private srcFolder;
private srcItem;
constructor() {
}
copy(srcFolder, srcItem) {
this.srcFolder = srcFolder;
this.srcItem = srcItem;
}
paste(destFolder) {
}
}
And here is my Component:
@Component({
selector: 'new-comp',
templateUrl: 'new-comp.html'
})
export class NewComp {
constructor(private clipboard: ClipService){
}
private keydown(event: KeyboardEvent) {
if (event.defaultPrevented) return;
let folder = this.folder.json;
let item = folder.activeItem;
if (event.ctrlKey && event.keyCode === 67) {
this.clipboard.copy(folder, item);
} else if (event.ctrlKey && event.keyCode === 86) {
this.clipboard.paste(this.finder.activeFolder);
}
}
}
Appreciate any help. Thank you.