From c54826be4bdf6d5d743cb2b27c42d322165358d7 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Thu, 28 Jul 2022 12:14:56 +0000 Subject: [PATCH] [FIX] web_editor: fix resizing columns out of parent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, it was possible to resize a column so that it overflows the right border of the row. Steps to reproduce the bug: 1. In website edit mode, drop a `media list` snippet in the page. 2. Select a column. 3. Resize the column by dragging its left side to the right to make it smaller. 4. Drag its right side to make it bigger and go until the edge of the editor => The column overflows and ends outside of the content zone. This commit prevents the column from overflowing when it has an offset. task-2837361 closes odoo/odoo#108218 X-original-commit: 1759079cbb084acac0616abfab84b83b1e62ae61 Signed-off-by: Bojabza Soukéina (sobo) --- .../static/src/js/editor/snippets.options.js | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index f195fff96f2..b3bca12b765 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -4654,24 +4654,35 @@ registry['sizing_x'] = registry.sizing.extend({ * @override */ _onResize: function (compass, beginClass, current) { - if (compass === 'w') { - // don't change the right border position when we change the offset (replace col size) - var beginCol = Number(beginClass.match(/col-lg-([0-9]+)|$/)[1] || 0); - var beginOffset = Number(beginClass.match(/offset-lg-([0-9-]+)|$/)[1] || beginClass.match(/offset-xl-([0-9-]+)|$/)[1] || 0); - var offset = Number(this.grid.w[0][current].match(/offset-lg-([0-9-]+)|$/)[1] || 0); - if (offset < 0) { - offset = 0; - } - var colSize = beginCol - (offset - beginOffset); - if (colSize <= 0) { - colSize = 1; - offset = beginOffset + beginCol - 1; - } - this.$target.attr('class', this.$target.attr('class').replace(/\s*(offset-xl-|offset-lg-|col-lg-)([0-9-]+)/g, '')); + if (compass === 'w' || compass === 'e') { + const beginOffset = Number(beginClass.match(/offset-lg-([0-9-]+)|$/)[1] || beginClass.match(/offset-xl-([0-9-]+)|$/)[1] || 0); - this.$target.addClass('col-lg-' + (colSize > 12 ? 12 : colSize)); - if (offset > 0) { - this.$target.addClass('offset-lg-' + offset); + if (compass === 'w') { + // don't change the right border position when we change the offset (replace col size) + var beginCol = Number(beginClass.match(/col-lg-([0-9]+)|$/)[1] || 0); + var offset = Number(this.grid.w[0][current].match(/offset-lg-([0-9-]+)|$/)[1] || 0); + if (offset < 0) { + offset = 0; + } + var colSize = beginCol - (offset - beginOffset); + if (colSize <= 0) { + colSize = 1; + offset = beginOffset + beginCol - 1; + } + this.$target.attr('class', this.$target.attr('class').replace(/\s*(offset-xl-|offset-lg-|col-lg-)([0-9-]+)/g, '')); + + this.$target.addClass('col-lg-' + (colSize > 12 ? 12 : colSize)); + if (offset > 0) { + this.$target.addClass('offset-lg-' + offset); + } + } else if (beginOffset > 0) { + const endCol = Number(this.grid.e[0][current].match(/col-lg-([0-9]+)|$/)[1] || 0); + // Avoids overflowing the grid to the right if the + // column size + the offset exceeds 12. + if ((endCol + beginOffset) > 12) { + this.$target[0].className = this.$target[0].className.replace(/\s*(col-lg-)([0-9-]+)/g, ''); + this.$target[0].classList.add('col-lg-' + (12 - beginOffset)); + } } } this._super.apply(this, arguments);