mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
revert base folder structure to src/*
This commit is contained in:
1 parent
afa8864452
commit
81c2a75d73
750 files changed
+44
-43
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// Helper for selecting element's text content and copy in clipboard
|
||||
|
||||
export function copyToClipboard(elem: HTMLElement, resetSelection = true): boolean {
|
||||
let clearSelection: () => void;
|
||||
if (isSelectable(elem)) {
|
||||
elem.select();
|
||||
clearSelection = () => elem.setSelectionRange(0, 0)
|
||||
}
|
||||
else {
|
||||
const selection = window.getSelection();
|
||||
selection.selectAllChildren(elem);
|
||||
clearSelection = () => selection.removeAllRanges();
|
||||
}
|
||||
const copyResult = document.execCommand("copy");
|
||||
if (resetSelection) clearSelection();
|
||||
return copyResult;
|
||||
}
|
||||
|
||||
function isSelectable(elem: HTMLElement): elem is HTMLInputElement {
|
||||
return !!(elem as HTMLInputElement).select;
|
||||
}
|
||||
Reference in new issue
Block a user