-
Notifications
You must be signed in to change notification settings - Fork 8
Add copy button to stack trace code blocks #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -230,6 +230,27 @@ summary:hover { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-size: 0.9375rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .copy-trace-btn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| margin-left: auto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display: inline-flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gap: 0.35rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| padding: 0.25rem 0.5rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-size: 0.75rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| background: #262626; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border: 1px solid #383838; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-radius: 4px; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: #a3a3a3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cursor: pointer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transition: color 0.15s, background 0.15s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .copy-trace-btn:hover { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| background: #333; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: #f472b6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .copy-trace-btn svg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flex-shrink: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+233
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Add empty lines before CSS rules for consistency. Stylelint flags missing empty lines before 🧹 Proposed formatting fix .hidden {
display: none;
}
+
.copy-trace-btn {
margin-left: auto;
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
background: `#262626`;
border: 1px solid `#383838`;
border-radius: 4px;
color: `#a3a3a3`;
cursor: pointer;
transition: color 0.15s, background 0.15s;
}
+
.copy-trace-btn:hover {
background: `#333`;
color: `#f472b6`;
}
+
.copy-trace-btn svg {
flex-shrink: 0;
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Stylelint (17.2.0)[error] 233-246: Expected empty line before rule (rule-empty-line-before) (rule-empty-line-before) [error] 247-250: Expected empty line before rule (rule-empty-line-before) (rule-empty-line-before) [error] 251-253: Expected empty line before rule (rule-empty-line-before) (rule-empty-line-before) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .hidden { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display: none; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,7 +58,13 @@ <h2>Help us fix it</h2> | |||||
| </div> | ||||||
|
|
||||||
| <details> | ||||||
| <summary>View Stack Trace</summary> | ||||||
| <summary> | ||||||
| View Stack Trace | ||||||
| <button class="copy-trace-btn" onclick="event.stopPropagation();var t=document.querySelector('.stacktrace').textContent;navigator.clipboard.writeText(t).then(function(){this.querySelector('span').textContent='Copied!';var b=this;setTimeout(function(){b.querySelector('span').textContent='Copy'},2e3)}.bind(this))" title="Copy stack trace"> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for clipboard API failure. Same issue as the standalone version—no 🛡️ Proposed fix with error handling- <button class="copy-trace-btn" onclick="event.stopPropagation();var t=document.querySelector('.stacktrace').textContent;navigator.clipboard.writeText(t).then(function(){this.querySelector('span').textContent='Copied!';var b=this;setTimeout(function(){b.querySelector('span').textContent='Copy'},2e3)}.bind(this))" title="Copy stack trace">
+ <button class="copy-trace-btn" onclick="event.stopPropagation();var t=document.querySelector('.stacktrace').textContent;navigator.clipboard.writeText(t).then(function(){this.querySelector('span').textContent='Copied!';var b=this;setTimeout(function(){b.querySelector('span').textContent='Copy'},2000)}.bind(this)).catch(function(){this.querySelector('span').textContent='Failed';var b=this;setTimeout(function(){b.querySelector('span').textContent='Copy'},2000)}.bind(this))" title="Copy stack trace">📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="14" height="14"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg> | ||||||
| <span>Copy</span> | ||||||
| </button> | ||||||
| </summary> | ||||||
| <div class="stacktrace">%STACKTRACE%</div> | ||||||
| </details> | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||||||
| import type { Parse, RemapAPIResponse } from "../lib/parser"; | ||||||||||||||||||||||||||||||||||||
| import { os_names } from "../lib/format"; | ||||||||||||||||||||||||||||||||||||
| import { os_names, addrsToPlainText } from "../lib/format"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import { parse } from "../lib/parser"; | ||||||||||||||||||||||||||||||||||||
| import { parseCacheKey, debounce, escapeHTML as eschtml } from "../lib/util"; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -191,11 +191,31 @@ const screens: Record<UIState, () => void> = { | |||||||||||||||||||||||||||||||||||
| out.innerHTML = /* html */ ` | ||||||||||||||||||||||||||||||||||||
| <div class='card'> | ||||||||||||||||||||||||||||||||||||
| ${cardHead()} | ||||||||||||||||||||||||||||||||||||
| <table><tbody>${list}</tbody></table> | ||||||||||||||||||||||||||||||||||||
| <div class='table-wrapper'> | ||||||||||||||||||||||||||||||||||||
| <table><tbody>${list}</tbody></table> | ||||||||||||||||||||||||||||||||||||
| <button class='copy-btn' title='Copy stack trace'> | ||||||||||||||||||||||||||||||||||||
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg> | ||||||||||||||||||||||||||||||||||||
| <span>Copy</span> | ||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||
| ${cardFooter()} | ||||||||||||||||||||||||||||||||||||
| <div class='spacing'>${issue}</div> | ||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const copyBtn = out.querySelector(".copy-btn") as HTMLButtonElement; | ||||||||||||||||||||||||||||||||||||
| if (copyBtn) { | ||||||||||||||||||||||||||||||||||||
| copyBtn.addEventListener("click", () => { | ||||||||||||||||||||||||||||||||||||
| const lines = addrsToPlainText(fetched!.commit.oid, fetched!.addresses); | ||||||||||||||||||||||||||||||||||||
| const text = `${parsed!.message}\n\n${lines.join("\n")}`; | ||||||||||||||||||||||||||||||||||||
| navigator.clipboard.writeText(text).then(() => { | ||||||||||||||||||||||||||||||||||||
| copyBtn.querySelector("span")!.textContent = "Copied!"; | ||||||||||||||||||||||||||||||||||||
| setTimeout(() => { | ||||||||||||||||||||||||||||||||||||
| copyBtn.querySelector("span")!.textContent = "Copy"; | ||||||||||||||||||||||||||||||||||||
| }, 2000); | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+211
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for clipboard API failure. The 🛡️ Proposed fix with error handling navigator.clipboard.writeText(text).then(() => {
copyBtn.querySelector("span")!.textContent = "Copied!";
setTimeout(() => {
copyBtn.querySelector("span")!.textContent = "Copy";
}, 2000);
+ }).catch(() => {
+ copyBtn.querySelector("span")!.textContent = "Failed";
+ setTimeout(() => {
+ copyBtn.querySelector("span")!.textContent = "Copy";
+ }, 2000);
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // When fetch fails, fallback to this screen. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,6 +286,40 @@ button:hover, | |
| } | ||
| } | ||
|
|
||
| .table-wrapper { | ||
| position: relative; | ||
| } | ||
|
|
||
| .copy-btn { | ||
| position: absolute; | ||
| top: 0; | ||
| right: 0; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: 0.35rem; | ||
| padding: 0.3rem 0.6rem; | ||
| font-size: 0.8rem; | ||
| background-color: var(--fn-bg); | ||
| border: 1px solid var(--fn-border); | ||
| border-radius: 6px; | ||
| color: var(--fg); | ||
| cursor: pointer; | ||
| opacity: 0.7; | ||
| transition: opacity 0.15s; | ||
| } | ||
|
|
||
| .copy-btn:hover { | ||
| opacity: 1; | ||
| background-color: var(--pink); | ||
| border-color: rgb(247, 97, 174); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Use modern color-function notation. Stylelint flags 🧹 Proposed fix .copy-btn:hover {
opacity: 1;
background-color: var(--pink);
- border-color: rgb(247, 97, 174);
+ border-color: rgb(247 97 174);
color: black;
}🧰 Tools🪛 Stylelint (17.2.0)[error] 314-314: Expected modern color-function notation (color-function-notation) (color-function-notation) 🤖 Prompt for AI Agents |
||
| color: black; | ||
| } | ||
|
|
||
| .copy-btn svg { | ||
| width: 14px; | ||
| height: 14px; | ||
| } | ||
|
|
||
| @media (max-width: 480px) { | ||
| .card { | ||
| margin-left: -1em; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for clipboard API failure.
The
navigator.clipboard.writeText()call has no.catch()handler. If clipboard access is denied (e.g., in non-secure contexts or when permissions are blocked), the promise rejects silently and the "Copied!" feedback never appears, leaving users confused.🛡️ Proposed fix with error handling
📝 Committable suggestion
🤖 Prompt for AI Agents