Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not update correct editor when there are multiple editors on the page. #1

Open
sanelson2000 opened this issue Jan 28, 2021 · 1 comment

Comments

@sanelson2000
Copy link

sanelson2000 commented Jan 28, 2021

I have a page with 2 tinymce editors on it. And just installed your code editor plugin (which is very nice, BTW). If I try to use the code editor plugin on the first editor, when I click Save, it overwrites the contents of the second editor with the value instead of updating the first. It appears that tinymce.activeEditor is not always returning the editor that the plugin was called from. I hacked around it by passing the editor variable to displayToxEditorModal and setting the id of the editor as a data attribute on the modal, which I then read back in saveContent()... But I'm sure there's probably a cleaner way to do it.

function displayToxEditorModal(e, display = true) {
  let el = document.getElementById('tox-codeeditor-wrap');
  if (display) {
    el.dataset.editor = e.id;
    el.style.display = "flex";
    el.focus();
    document.body.classList.add('tox-codeeditor__disable-scroll');
  } else {
    e = e || tinymce.get(el.dataset.editor);
    el.style.display = "none";
    document.body.classList.remove('tox-codeeditor__disable-scroll');
    e.focus();
  }
}

function saveContent() {
  let el = document.getElementById('tox-codeeditor-wrap');
  let e = tinymce.get(el.dataset.editor);
  e.focus();
  e.undoManager.transact(function() {
    e.setContent(aceEditor.getValue())
  });
  e.selection.setCursorLocation();
  e.nodeChanged();
  displayToxEditorModal(e,false);
}
@prathamVaidya
Copy link

@sanelson2000 I don't think this plugin is maintained any further. For anyone landing here in future, Try supercode plugin that I created for tinyMCE editor. It fixes all these issues and offers more.

chrome-capture-2024-4-7 (1)

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

No branches or pull requests

2 participants