Skip to content

Commit

Permalink
Resolves issues with Firefox __caret and toolbar overlapping codemirr…
Browse files Browse the repository at this point in the history
…or CONTENT-964 (#13)
  • Loading branch information
rjpepmeyer authored Jun 21, 2021
1 parent e15c651 commit 5f65351
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions plugins/codemirror/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {

function showSourceEditor() {
// Insert caret marker
if (document && document.activeElement) {
document.activeElement.blur();
}
editor.focus();
editor.selection.collapse(true);
// Preserve deliberate line-spacing at the caret position
Expand All @@ -36,6 +33,11 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {
scrollTo(0, 0);

const sourceEditorTargetContent = editor.contentDocument;

const toolbars = Array.from(sourceEditorTargetContent.querySelectorAll('.mce-tinymce-inline'));
toolbars.forEach(toolbar => {
toolbar.classList.add('hidden-toolbar');
});
var config = {
title: 'HTML source code',
url: url + '/source.html',
Expand All @@ -52,9 +54,17 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {
details: doc
}));
doc.contentWindow.submit();
toolbars.forEach(toolbar => {
toolbar.classList.remove('hidden-toolbar');
});
win.close();
}},
{ text: 'Cancel', onclick: 'close' }
{ text: 'Cancel', onclick: function () {
toolbars.forEach(toolbar => {
toolbar.classList.remove('hidden-toolbar');
});
win.close();
}}
]
};

Expand All @@ -67,12 +77,13 @@ tinymce.PluginManager.add('codemirror', function(editor, url) {
//scroll back to original position
scrollTo(oldPos.x, oldPos.y);

editor.targetElm.blur();
};

// If either the .addButton.title or .addMenuItem.text changes, this will break some logic in
// the page editor for disabling buttons (save, etc) in the header.
// If either the .addButton.title or .addMenuItem.text changes, this will break some logic in
// the page editor for disabling buttons (save, etc) in the header.
// https://github.com/Banno/platform-ux/pull/8418/files#diff-93d7632a21b27d323a46cfd5939b6758R178

// Add a button to the button bar
editor.addButton('code', {
title: 'Source code',
Expand Down
1 change: 1 addition & 0 deletions plugins/codemirror/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
head.appendChild(div);

// Set CodeMirror cursor and bookmark to same position as cursor was in TinyMCE:
editor.dom.remove(editor.dom.select('#__caret'));
var html = editor.getContent({source_view: true});
editor.selection.getBookmark();
html = html.replace(/<span\s+class="CmCaReT"([^>]*)>([^<]*)<\/span>/gm, String.fromCharCode(chr));
Expand Down

0 comments on commit 5f65351

Please sign in to comment.