Skip to content

Commit d8581d0

Browse files
committed
[IMP] devtools: copy component name to clipboard
This commit allows the user to simply click on the selected component of the details window to copy its name to the clipboard.
1 parent fb7d25b commit d8581d0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tools/devtools/src/devtools_app/devtools_window/components_tab/details_window/details_window.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
<div class="panel-top d-flex align-items-center">
55
<div class="ms-1 p-1 text-truncate" style="width: 100%;">
66
<span t-if="store.activeComponent.path.length > 1">&lt;</span>
7-
<b style="color: var(--component-color); cursor: pointer;" t-on-mouseover.stop="() => this.store.highlightComponent(this.store.activeComponent.path)" t-on-click.stop="() => this.store.focusSelectedComponent()" t-on-contextmenu.prevent="openMenu" t-esc="store.activeComponent.name"/>
7+
<b
8+
style="color: var(--component-color); cursor: pointer;"
9+
t-on-mouseover.stop="() => this.store.highlightComponent(this.store.activeComponent.path)"
10+
t-on-click.stop="() => this.store.onActiveComponentClick()"
11+
t-on-contextmenu.prevent="openMenu"
12+
t-esc="store.activeComponent.name"
13+
/>
814
<span t-if="store.activeComponent.path.length > 1">&gt;</span>
915
<span class="version" t-else="">owl=<t t-esc="store.activeComponent.version"/></span>
1016
</div>

tools/devtools/src/devtools_app/store/store.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,9 @@ export const store = reactive({
608608
},
609609

610610
// Center the view around the currently selected component
611-
focusSelectedComponent() {
611+
onActiveComponentClick() {
612612
this.selectedElement.scrollIntoView({ block: "center", behavior: "smooth" });
613+
copyToClipboard(this.activeComponent.name);
613614
},
614615

615616
// Toggle the recording of events in the page
@@ -1055,3 +1056,21 @@ async function evalInWindow(code, frameUrl = "top") {
10551056
}
10561057
});
10571058
}
1059+
1060+
function copyToClipboard(text) {
1061+
// This is crappy but it seems like document.execCommand is the only remaining way to
1062+
// copy text to clipboard in a devtools extension (even though it is marked as deprecated)
1063+
// since navigator.clipboard.writeText has permission issues inside iframes (and the devtools
1064+
// panel is mounted inside an iframe)
1065+
const textarea = document.createElement("textarea");
1066+
textarea.value = text;
1067+
textarea.style.opacity = "0";
1068+
document.body.appendChild(textarea);
1069+
textarea.select();
1070+
try {
1071+
document.execCommand("copy");
1072+
} catch (err) {
1073+
console.error("Copy failed", err);
1074+
}
1075+
document.body.removeChild(textarea);
1076+
}

0 commit comments

Comments
 (0)