Skip to content

armgit / Cairn

Public Imported from GitHub
0

Cairn is a general-purpose AI state-space search engine, validated first on autonomous penetration testing. Sometimes misspelled as Carin.

feat: implement clipboard copy fallback

leixiao619c33c449dd
diff --git a/cairn/src/cairn/server/static/index.html b/cairn/src/cairn/server/static/index.html
index b62714c..3040c09 100644
--- a/cairn/src/cairn/server/static/index.html
+++ b/cairn/src/cairn/server/static/index.html
@@ -1403,18 +1403,38 @@ function cairnApp() {
async copyYamlPreview() {
if (!this.yamlPreviewText) return;
- if (!navigator.clipboard?.writeText) {
- this.showToast('Copy not supported', 'error');
- return;
- }
try {
- await navigator.clipboard.writeText(this.yamlPreviewText);
+ await this.copyText(this.yamlPreviewText);
this.showToast('Copied');
} catch {
this.showToast('Copy failed', 'error');
}
},
+ async copyText(text) {
+ if (navigator.clipboard?.writeText) {
+ await navigator.clipboard.writeText(text);
+ return;
+ }
+ const textarea = document.createElement('textarea');
+ textarea.value = text;
+ textarea.setAttribute('readonly', '');
+ textarea.style.position = 'fixed';
+ textarea.style.top = '0';
+ textarea.style.left = '-9999px';
+ textarea.style.opacity = '0';
+ document.body.appendChild(textarea);
+ textarea.select();
+ textarea.setSelectionRange(0, textarea.value.length);
+ try {
+ if (!document.execCommand('copy')) {
+ throw new Error('copy command rejected');
+ }
+ } finally {
+ document.body.removeChild(textarea);
+ }
+ },
+
highlightYaml(text) {
const lines = String(text ?? '').split('\n');
let currentSection = '';