Skip to content

Fix: Preserve CKEditor5 instances in original blocks during copy operation#218

Closed
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-cke5-copy-issue
Closed

Fix: Preserve CKEditor5 instances in original blocks during copy operation#218
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-cke5-copy-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 26, 2025

When copying a block containing CKEditor5, the editor instance was removed from the original block due to jQuery's clone() copying the entire CKEditor5 UI structure (.ck-editor elements), which interfered with the active editor instance.

Changes

Core Fix (assets/mblock.js)

  • Modified MBlockClipboard.copy() to temporarily detach CKE5 UI elements before cloning using jQuery's .detach()
  • Reattach UI elements to original block after cloning completes
  • Added validation to verify parent elements exist in DOM before reattachment
  • Error handling with try-catch for graceful failure

Documentation

  • Added inline documentation explaining the issue and solution approach
  • Updated README to clarify CKEditor5 is supported (vs CKEditor4 which is not)

Technical Approach

// Before cloning: detach CKE5 UI elements
const cke5Editors = [];
item.find('.cke5-editor').each(function() {
    const $textarea = $(this);
    const $ckeUI = $textarea.next('.ck-editor');
    if ($ckeUI.length) {
        cke5Editors.push({ ckeUI: $ckeUI, parent: $ckeUI.parent(), nextSibling: $ckeUI.next() });
        $ckeUI.detach(); // Preserve events/data, just remove from DOM
    }
});

// Clone item (now only textareas, not CKE5 UI)
const clonedItem = item.clone(true, true);

// Restore CKE5 UI to original block
cke5Editors.forEach(editor => {
    if (editor.parent && document.contains(editor.parent[0])) {
        editor.ckeUI.insertBefore(editor.nextSibling) || editor.parent.append(editor.ckeUI);
    }
});

This ensures the original block's CKEditor5 instance remains intact while the cloned item contains only the textarea for proper reinitialization on paste.

Original prompt

This section details on the original issue you should resolve

<issue_title>CKE5 Problem beim Kopieren</issue_title>
<issue_description>Wenn ein block mit CKE5 kopiert wird, wird cke5 im original entfernt aber nicht wiederhergestellt.
Alle anderen Blöcke bleiben davon unberührt das ist gut </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 26, 2025 11:03
Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CKE5 copy issue with restoration Fix: Preserve CKEditor5 instances in original blocks during copy operation Nov 26, 2025
Copilot AI requested a review from skerbis November 26, 2025 11:10
@skerbis
Copy link
Copy Markdown
Member

skerbis commented Nov 26, 2025

du musst das build noch erstellen @copilot

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 26, 2025

du musst das build noch erstellen @copilot

Der Build ist bereits erstellt und committed! Die Dateien assets/mblock.min.js und assets/mblock.min.js.map wurden in den Commits b369919, 34a723e und 518cd70 aktualisiert. Ich habe gerade nochmal gebaut um sicherzustellen - keine Änderungen nötig, alles ist aktuell. ✅

@skerbis skerbis closed this Nov 26, 2025
@skerbis skerbis deleted the copilot/fix-cke5-copy-issue branch November 26, 2025 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CKE5 Problem beim Kopieren

2 participants