Get rid of the unwanted tooltip copying (final) (#7459)

This commit is contained in:
Philip Allgaier 2020-10-27 20:20:15 +01:00 committed by GitHub
parent ba99d1a10d
commit 58a58906e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,7 @@ class SystemHealthCard extends LitElement {
}
if (domain !== "homeassistant") {
sections.push(
html` <h3>${domainToName(this.hass.localize, domain)}</h3> `
html`<h3>${domainToName(this.hass.localize, domain)}</h3>`
);
}
sections.push(html`
@ -128,30 +128,27 @@ class SystemHealthCard extends LitElement {
}
private _copyInfo(): void {
// We have to copy title text and content separately, because
// copying the whole <ha-card> would also copy the tooltip text.
const selection = window.getSelection()!;
selection.removeAllRanges();
let copyElement = this.shadowRoot?.querySelector(
".card-header-text"
) as HTMLElement;
let range = document.createRange();
range.selectNodeContents(copyElement);
selection.addRange(range);
copyElement = this.shadowRoot?.querySelector(
const copyElement = this.shadowRoot?.querySelector(
".card-content"
) as HTMLElement;
range = document.createRange();
// Add temporary heading (fixed in EN since usually executed to provide support data)
const tempTitle = document.createElement("h3");
tempTitle.innerText = "System Health";
copyElement.insertBefore(tempTitle, copyElement.firstElementChild);
const selection = window.getSelection()!;
selection.removeAllRanges();
const range = document.createRange();
range.selectNodeContents(copyElement);
selection.addRange(range);
document.execCommand("copy");
window.getSelection()!.removeAllRanges();
// Remove temporary heading again
copyElement.removeChild(tempTitle);
this._toolTip!.show();
setTimeout(() => this._toolTip?.hide(), 3000);
}