(text: string)
| 376 | return selections.map((selection) => model.getValueInRange(selection)).join(model.getEOL()); |
| 377 | }; |
| 378 | const writeClipboardText = async (text: string) => { |
| 379 | if (navigator.clipboard?.writeText) { |
| 380 | try { |
| 381 | await navigator.clipboard.writeText(text); |
| 382 | return; |
| 383 | } catch { |
| 384 | // 失败时回落到下方的 execCommand 分支 |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | const textarea = document.createElement("textarea"); |
| 389 | textarea.value = text; |
| 390 | textarea.style.position = "fixed"; |
| 391 | textarea.style.left = "-9999px"; |
| 392 | textarea.style.top = "-9999px"; |
| 393 | document.body.appendChild(textarea); |
| 394 | textarea.focus(); |
| 395 | textarea.select(); |
| 396 | const ok = document.execCommand("copy"); |
| 397 | textarea.remove(); |
| 398 | if (!ok) throw new Error("copy failed"); |
| 399 | }; |
| 400 | const copyEditorSelection = (editor: editor.ICodeEditor) => { |
| 401 | const text = getSelectedText(editor); |
| 402 | if (!text) return; |
no test coverage detected