]> BookStack Code Mirror - bookstack/commitdiff
CM6: Further fixes/improvements after testing 3617/head
authorDan Brown <redacted>
Tue, 18 Apr 2023 14:08:17 +0000 (15:08 +0100)
committerDan Brown <redacted>
Tue, 18 Apr 2023 14:08:17 +0000 (15:08 +0100)
- 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
resources/js/services/clipboard.js
resources/sass/_codemirror.scss
resources/sass/_forms.scss

index 1064feda437c3ab981ada45db8e3d5ad63b518d8..32c25d401f8ee497e775d25ab5e02b56959f6459 100644 (file)
@@ -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);
index 6e59270a9b2cfea74e9102b8e102bc7ef0025660..c0b0fbfab6260c6f84f06bbf6755e650a1e6d47e 100644 (file)
@@ -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
index ed56ac8d4838dab9b58de296b8d7439200324bea..0fd347cf893a3bc37f1f5379e849aa6140f552a9 100644 (file)
@@ -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;
 }
 
index 84825ddc6698e550ddd08333c593db5662a87aae..37f8f1bfcf720d28568eb522033a845fc27629ab 100644 (file)
@@ -86,6 +86,8 @@
 .markdown-editor-wrap .cm-editor {
   flex: 1;
   max-width: 100%;
+  border: 0;
+  margin: 0;
 }
 
 .markdown-panel-divider {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.