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

Pasting content does not remove trailing BR tag #392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/minified/wysihtml.all-commands.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/minified/wysihtml.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/minified/wysihtml.min.map

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions dist/wysihtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -12134,7 +12134,7 @@ wysihtml.Commands = Base.extend(

function getOptions(value) {
var options = typeof value === 'object' ? value : {'href': value};
return wysihtml.lang.object({}).merge(nodeOptions).merge({'attribute': value}).get();
return wysihtml.lang.object({}).merge(nodeOptions).merge({'attribute': options}).get();
}

wysihtml.commands.createLink = {
Expand Down Expand Up @@ -14714,8 +14714,8 @@ wysihtml.views.View = Base.extend(
// Ensures when editor is empty and not line breaks mode, the inital state has a paragraph in it on focus with caret inside paragraph
if (!this.config.useLineBreaks) {
dom.observe(this.element, ["focus"], function() {
if (that.isEmpty()) {
setTimeout(function() {
setTimeout(function() {
if (that.isEmpty()) {
var paragraph = that.doc.createElement("P");
that.element.innerHTML = "";
that.element.appendChild(paragraph);
Expand All @@ -14725,8 +14725,8 @@ wysihtml.views.View = Base.extend(
} else {
that.selection.selectNode(paragraph, true);
}
}, 0);
}
}
}, 0);
});
}

Expand Down Expand Up @@ -15917,12 +15917,12 @@ wysihtml.views.Textarea = wysihtml.views.View.extend(
uneditableContainer: "wysihtml-uneditable-container"
},
// Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
// Also copied source is based directly on selection -
// Also copied source is based directly on selection -
// (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
// If falsy value is passed source override is also disabled
copyedFromMarking: '<meta name="copied-from" content="wysihtml">'
},

constructor: function(editableElement, config) {
this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
this.config = wysihtml.lang.object({}).merge(this.defaults).merge(config).get();
Expand Down Expand Up @@ -15970,7 +15970,7 @@ wysihtml.views.Textarea = wysihtml.views.View.extend(
}
this.runEditorExtenders();
},

runEditorExtenders: function() {
wysihtml.editorExtenders.forEach(function(extender) {
extender(this);
Expand Down Expand Up @@ -16096,6 +16096,21 @@ wysihtml.views.Textarea = wysihtml.views.View.extend(
"uneditableClass": this.config.classNames.uneditableContainer
});
this.composer.selection.deleteContents();

if (!this.config.useLineBreaks && this.composer.selection.caretIsInTheEndOfNode()) {
var sel = this.composer.selection.getSelection(),
aNode = sel.anchorNode,
childNode;

if (aNode && aNode.nodeName === 'P' && aNode.childNodes.length === 1) {
childNode = aNode.firstChild;

if (childNode.nodeName === 'BR') {
aNode.removeChild(childNode);
}
}
}

this.composer.selection.insertHTML(cleanHtml);
}
});
Expand Down
21 changes: 18 additions & 3 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
uneditableContainer: "wysihtml-uneditable-container"
},
// Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
// Also copied source is based directly on selection -
// Also copied source is based directly on selection -
// (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
// If falsy value is passed source override is also disabled
copyedFromMarking: '<meta name="copied-from" content="wysihtml">'
},

constructor: function(editableElement, config) {
this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
this.config = wysihtml.lang.object({}).merge(this.defaults).merge(config).get();
Expand Down Expand Up @@ -131,7 +131,7 @@
}
this.runEditorExtenders();
},

runEditorExtenders: function() {
wysihtml.editorExtenders.forEach(function(extender) {
extender(this);
Expand Down Expand Up @@ -257,6 +257,21 @@
"uneditableClass": this.config.classNames.uneditableContainer
});
this.composer.selection.deleteContents();

if (!this.config.useLineBreaks && this.composer.selection.caretIsInTheEndOfNode()) {
var sel = this.composer.selection.getSelection(),
aNode = sel.anchorNode,
childNode;

if (aNode && aNode.nodeName === 'P' && aNode.childNodes.length === 1) {
childNode = aNode.firstChild;

if (childNode.nodeName === 'BR') {
aNode.removeChild(childNode);
}
}
}

this.composer.selection.insertHTML(cleanHtml);
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/views/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@
// Ensures when editor is empty and not line breaks mode, the inital state has a paragraph in it on focus with caret inside paragraph
if (!this.config.useLineBreaks) {
dom.observe(this.element, ["focus"], function() {
if (that.isEmpty()) {
setTimeout(function() {
setTimeout(function() {
if (that.isEmpty()) {
var paragraph = that.doc.createElement("P");
that.element.innerHTML = "";
that.element.appendChild(paragraph);
Expand All @@ -436,8 +436,8 @@
} else {
that.selection.selectNode(paragraph, true);
}
}, 0);
}
}
}, 0);
});
}

Expand Down