Skip to content

Commit 6384208

Browse files
committed
add a copy button to copy expression
1 parent db7f698 commit 6384208

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

dev/lib/codemirror.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,21 @@ function elt(tag, content, className, style) {
8080
function eltP(tag, content, className, style) {
8181
var e = elt(tag, content, className, style)
8282
e.setAttribute("role", "presentation")
83+
e.setAttribute("id", "presentation")
8384
return e
8485
}
86+
function copyExpression() {
87+
var expressionText = ""
88+
document.getElementById("presentation").childNodes.forEach((child) => {
89+
expressionText += child.innerText
90+
})
91+
navigator.clipboard.writeText(expressionText)
92+
93+
document.getElementById("copyExpressionButton").innerText= "Copied !"
94+
setTimeout(() => {
95+
document.getElementById("copyExpressionButton").innerText= "Copy Expression"
96+
}, 800);
97+
}
8598

8699
var range
87100
if (document.createRange) { range = function(node, start, end, endNode) {

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ <h1 class="label">Menu</h1>
157157
<section class="expression">
158158
<header>
159159
<h1>Expression</h1>
160+
<div class="button flavor" onclick="copyExpression();">
161+
<svg xmlns="http://www.w3.org/2000/svg" x="0px"y="0px" xml:space="preserve" style="enable-background:new 0 0 460 460;right: .25em;position: relative;" viewBox="0 0 460 460" class="icon">
162+
<g>
163+
<path d="M425.934,0H171.662c-18.122,0-32.864,14.743-32.864,32.864v77.134h30V32.864c0-1.579,1.285-2.864,2.864-2.864h254.272
164+
c1.579,0,2.864,1.285,2.864,2.864v254.272c0,1.58-1.285,2.865-2.864,2.865h-74.729v30h74.729
165+
c18.121,0,32.864-14.743,32.864-32.865V32.864C458.797,14.743,444.055,0,425.934,0z"></path>
166+
<path d="M288.339,139.998H34.068c-18.122,0-32.865,14.743-32.865,32.865v254.272C1.204,445.257,15.946,460,34.068,460h254.272
167+
c18.122,0,32.865-14.743,32.865-32.864V172.863C321.206,154.741,306.461,139.998,288.339,139.998z M288.341,430H34.068
168+
c-1.58,0-2.865-1.285-2.865-2.864V172.863c0-1.58,1.285-2.865,2.865-2.865h254.272c1.58,0,2.865,1.285,2.865,2.865v254.273h0.001
169+
C291.206,428.715,289.92,430,288.341,430z"></path>
170+
</g>
171+
</svg>
172+
<span class="label" id="copyExpressionButton">Copy Expression</span>
173+
</div>
160174
<div class="controlbar">
161175
<div class="button flavor">
162176
<svg class="icon"><use xlink:href="#code"></use></svg>

0 commit comments

Comments
 (0)