From baf5edd73a12e1305f147f0082f00662d50edd0a Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 18 Apr 2023 15:08:17 +0100 Subject: [PATCH] CM6: Further fixes/improvements after testing - Updated event naming to be "cm6" when codemirror-specific. - Removed cm block border in md editor to prevent double bordering. - Updated copy handling to fallback to execCommand. --- resources/js/code/index.mjs | 2 +- resources/js/services/clipboard.js | 16 ++++++++++++++-- resources/sass/_codemirror.scss | 2 +- resources/sass/_forms.scss | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/resources/js/code/index.mjs b/resources/js/code/index.mjs index 1064feda4..32c25d401 100644 --- a/resources/js/code/index.mjs +++ b/resources/js/code/index.mjs @@ -196,7 +196,7 @@ export function markdownEditor(elem, onChange, domEventHandlers, keyBindings) { }; // Emit a pre-event public event to allow tweaking of the configure before view creation. - window.$events.emitPublic(elem, 'editor-markdown-cm::pre-init', {cmEditorViewConfig: config}); + window.$events.emitPublic(elem, 'editor-markdown-cm6::pre-init', {editorViewConfig: config}); // Create editor view, hide original input const ev = createView(config); diff --git a/resources/js/services/clipboard.js b/resources/js/services/clipboard.js index 6e59270a9..c0b0fbfab 100644 --- a/resources/js/services/clipboard.js +++ b/resources/js/services/clipboard.js @@ -51,8 +51,20 @@ export class Clipboard { } } -export function copyTextToClipboard(text) { - return navigator.clipboard.writeText(text); +export async function copyTextToClipboard(text) { + if (window.isSecureContext && navigator.clipboard) { + await navigator.clipboard.writeText(text); + return; + } + + // Backup option where we can't use the navigator.clipboard API + const tempInput = document.createElement("textarea"); + tempInput.style = "position: absolute; left: -1000px; top: -1000px;"; + tempInput.value = text; + document.body.appendChild(tempInput); + tempInput.select(); + document.execCommand("copy"); + document.body.removeChild(tempInput); } export default Clipboard; \ No newline at end of file diff --git a/resources/sass/_codemirror.scss b/resources/sass/_codemirror.scss index ed56ac8d4..0fd347cf8 100644 --- a/resources/sass/_codemirror.scss +++ b/resources/sass/_codemirror.scss @@ -6,11 +6,11 @@ font-size: 12px; border: 1px solid #ddd; line-height: 1.4; + margin-bottom: $-l; } .page-content .cm-editor, .CodeMirrorContainer .cm-editor { - margin-bottom: $-l; border-radius: 4px; } diff --git a/resources/sass/_forms.scss b/resources/sass/_forms.scss index 84825ddc6..37f8f1bfc 100644 --- a/resources/sass/_forms.scss +++ b/resources/sass/_forms.scss @@ -86,6 +86,8 @@ .markdown-editor-wrap .cm-editor { flex: 1; max-width: 100%; + border: 0; + margin: 0; } .markdown-panel-divider {