Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated normalise line breaks addon

  • Loading branch information...
commit 8da82477906138397fdbcba46745bc2bf37071aa 1 parent 7b7d47a
@faceleg faceleg authored
View
69 src/plugins/normalise-line-breaks/jquery.ui.editor.normalise-line-breaks.js
@@ -50,42 +50,59 @@ $.ui.editor.registerPlugin('normaliseLineBreaks', /** @lends $.editor.plugin.nor
hotkeys: {
'return': {
'action': function() {
- this.insertBreak(this.options.enter, this.options.enterValidTags);
+
+ selectionDestroy();
+
+ var selectionEmpty = selectionIsEmpty();
+ var selectionIsAtStart = selectionAtStartOfElement();
+ var selectionIsAtEnd = selectionAtEndOfElement();
+
+ var breakId = this.options.baseClass + '-enter-break';
+ var breakElement = $(this.options.enter).attr('id', breakId);
+
+ selectionReplaceWithinValidTags(breakElement, this.options.enterValidTags);
+
+ breakElement = $('#' + breakId).removeAttr('id');
+ if (selectionEmpty) {
+ if (selectionIsAtStart) {
+ selectionSelectStart(breakElement.next());
+ } else if(selectionIsAtEnd) {
+ selectionSelectStart(breakElement);
+ } else {
+ selectionSelectStart(breakElement.next());
+ var previousSibling = breakElement.prev();
+ if (previousSibling && !$.trim(previousSibling.html()) == '' && elementOuterHtml(previousSibling) != this.options.enter) {
+ breakElement.remove();
+ }
+ }
+ } else {
+ selectionSelectStart(breakElement.next());
+ breakElement.remove();
+ }
},
restoreSelection: false
},
'return+shift': {
'action': function() {
- this.insertBreak(this.options.shiftEnter, this.options.shiftEnterValidTags);
- },
- restoreSelection: false
- }
- },
+ selectionDestroy();
- /**
- * Replace selection with given breakHtml
- * @param {String} breakHtml The HTML to replace selection with.
- * @param {Array} breakValidTags Array of tag names within which the replaceHtml is valid.
- */
- insertBreak: function(breakHtml, breakValidTags) {
+ var breakId = this.options.baseClass + '-enter-break';
- selectionDestroy();
+ var breakElement = $(breakHtml)
+ .attr('id', breakId)
+ .appendTo('body');
- var breakId = this.options.baseClass + '-enter-break';
+ if (this.options.shiftEnterValidTags) {
+ selectionReplaceWithinValidTags(this.options.shiftEnter, this.options.shiftEnterValidTags);
+ } else {
+ selectionReplace(breakElement);
+ }
- var breakElement = $(breakHtml)
- .attr('id', breakId)
- .appendTo('body');
+ var select = $('#' + breakId).removeAttr('id').next();
- if (breakValidTags) {
- selectionReplaceWithinValidTags(breakElement, breakValidTags);
- } else {
- selectionReplace(breakElement);
+ selectionSelectStart(select);
+ },
+ restoreSelection: false
}
-
- var select = $('#' + breakId).removeAttr('id').next();
-
- selectionSelectStart(select);
}
-
});
Please sign in to comment.
Something went wrong with that request. Please try again.