Last active
February 12, 2021 10:03
-
-
Save jcmoore/0c1afb8552cccb0c2ab0039a2e3e87ac to your computer and use it in GitHub Desktop.
VS Code Augmentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// document.querySelector(".monaco-breadcrumbs").addEventListener("click", copyMonacoBreadcrumbFileContextToClipboard) | |
function copyMonacoBreadcrumbFileContextToClipboard () { | |
const text = document.querySelector(".monaco-breadcrumbs").innerText; | |
const str = text.slice(text.indexOf("\n", text.lastIndexOf(".") + 1) + 1) | |
.split("\n") | |
.map((line, index) => new Array(index).fill("|\t").join("") + line) | |
.join("\n"); | |
const el = document.createElement('textarea'); | |
el.value = str; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
alert(str + "\n\ncopied to clipboard"); | |
} | |
// document.querySelector(".margin-view-overlays").addEventListener("mousedown", copyMarginViewOverlaysLineNumbersToClipboard) | |
// document.querySelector(".margin-view-overlays").addEventListener("mouseup", copyMarginViewOverlaysLineNumbersToClipboard) | |
function copyMarginViewOverlaysLineNumbersToClipboard(ev) { | |
switch (ev.type) { | |
case "mousedown": { | |
copyMarginViewOverlaysLineNumbersToClipboard.prototype.startLineNumber = Number(ev.target.textContent) || undefined; | |
return; | |
} | |
case "mouseup": { | |
const endLineNumber = Number(ev.target.textContent) || undefined; | |
const { startLineNumber = endLineNumber } = copyMarginViewOverlaysLineNumbersToClipboard.prototype; | |
copyMarginViewOverlaysLineNumbersToClipboard.prototype.startLineNumber = undefined; | |
const str = endLineNumber - startLineNumber === 0 ? "#L"+startLineNumber | |
: endLineNumber - startLineNumber > 0 ? "#L"+startLineNumber+"-L"+endLineNumber | |
: endLineNumber - startLineNumber < 0 ? "#L"+endLineNumber+"-L"+startLineNumber | |
: ""; | |
if (!str) return; | |
const el = document.createElement('textarea'); | |
el.value = str; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
alert(str + "\n\ncopied to clipboard"); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment