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

fix issue with chrome wrapping contents with span #873

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/trumbowyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
t.$ed
.on('dblclick', 'img', t.o.imgDblClickHandler)
.on('keydown', function (e) {
// append flags to differentiate Chrome spans
var keyCode = e.which;
if (keyCode === 8 || keyCode === 13 || keyCode === 46) {
t.toggleSpan(true);
}
if ((e.ctrlKey || e.metaKey) && !e.altKey) {
ctrl = true;
var key = t.keys[String.fromCharCode(e.which).toUpperCase()];
Expand Down Expand Up @@ -597,6 +602,11 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
return;
}

// remove Chrome generated span tags
if (keyCode === 8 || keyCode === 13 || keyCode === 46) {
t.toggleSpan();
}

if ((e.ctrlKey || e.metaKey) && (keyCode === 89 || keyCode === 90)) {
t.$c.trigger('tbwchange');
} else if (!ctrl && keyCode !== 17) {
Expand Down Expand Up @@ -1022,6 +1032,18 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
}, 0);
},

// Remove or add flags to span tags to remove Chrome generated spans
toggleSpan: function (addFlag) {
var t = this;
t.$ed.find('span').each(function () {
if (addFlag === true) {
$(this).attr('data-tbw-flag', true);
} else {
$(this).attr('data-tbw-flag') ? $(this).removeAttr('data-tbw-flag') : $(this).contents().unwrap();
}
});
},

// Open dropdown when click on a button which open that
dropdown: function (name) {
var t = this,
Expand Down