summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/wysiwyg/plugin
diff options
context:
space:
mode:
authorAntoine Guenet <age@odoo.com>2019-02-19 10:53:55 +0000
committerAntoine Guenet <age@odoo.com>2019-02-21 09:13:30 +0000
commit00a78af98eaacbf582233956777263185685d886 (patch)
tree4eec7bc8fa0271e131c199f1b859a69be46d70eb /addons/web_editor/static/src/js/wysiwyg/plugin
parent8b8d6d0a5b2ab6255f9fd3bec4284f371f1282c8 (diff)
[FIX] web_editor: stop removing empty block after deleting its contents
Deleting all the contents of a block node replaced it with a blank paragraph node. To restore v12 behavior, it should only do that when pressing backspace in an already empty block, which is now what it does.
Diffstat (limited to 'addons/web_editor/static/src/js/wysiwyg/plugin')
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js b/addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js
index 3db30752277..0cb451c100d 100644
--- a/addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js
+++ b/addons/web_editor/static/src/js/wysiwyg/plugin/keyboard.js
@@ -42,7 +42,6 @@ var KeyboardPlugin = AbstractPlugin.extend({
range = direction === 'prev' ? this._insertInvisibleCharAfterSingleBR(range) : range;
range = this._rerangeOutOfBR(range, direction);
range = this._cleanRangeAfterDeletion(range);
- range = this._replaceEmptyParentWithEmptyP(range);
return range;
},
/**
@@ -219,8 +218,15 @@ var KeyboardPlugin = AbstractPlugin.extend({
* @returns {Boolean} true if case handled
*/
_handleDeletion: function (direction) {
- var didDeleteNodes = this.context.invoke('HelperPlugin.deleteSelection')
var range = this.context.invoke('editor.createRange');
+ range = direction === 'prev' && this._replaceEmptyParentWithEmptyP(range);
+ if (range) {
+ range = this._afterDeletion(range, direction);
+ range.select();
+ return true;
+ }
+ var didDeleteNodes = this.context.invoke('HelperPlugin.deleteSelection');
+ range = this.context.invoke('editor.createRange');
var wasOnStartOfBR = direction === 'prev' && !range.so && range.sc.tagName === 'BR';
this._removeNextEmptyUnbreakable(range.sc);
@@ -837,23 +843,27 @@ var KeyboardPlugin = AbstractPlugin.extend({
*
* @private
* @param {Object} range
- * @returns {Object} range
+ * @returns {Object|undefined} range
*/
_replaceEmptyParentWithEmptyP: function (range) {
- if (range.sc === this.editable || range.sc.parentNode === this.editable) {
- return range;
+ var node = range.sc.childElementCount === 1 && range.sc.firstChild.tagName === 'BR' ? range.sc.firstChild : range.sc;
+ if (node === this.editable || !node.parentNode || node.parentNode === this.editable) {
+ return;
}
- var node = dom.isVoid(range.sc) && range.sc.parentNode ? range.sc.parentNode : range.sc;
- var parentOnlyHasNode = node.parentNode && this.context.invoke('HelperPlugin.onlyContains', node.parentNode, node);
- if (dom.isEmpty(node) && node.tagName !== 'LI' && parentOnlyHasNode) {
+ if (
+ dom.isEmpty(node) &&
+ this.context.invoke('HelperPlugin.onlyContains', node.parentNode, node) &&
+ ['LI', 'P'].indexOf(node.parentNode.tagName) === -1
+ ) {
var emptyP = this.document.createElement('p');
var br = this.document.createElement('br');
$(emptyP).append(br);
- $(node).before(emptyP).remove();
+ $(node.parentNode).before(emptyP).remove();
range.sc = range.ec = br;
range.so = range.eo = 0;
+ return range.collapse(true);
}
- return range;
+ return;
},
/**
* Replace all leading space from a text node with one non-breakable space.