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);