From 0f80e18f4a43cde9fd111547b5c3cef63a09be26 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Aug 2016 16:39:33 +0200 Subject: [PATCH] [FIX] web: ace: implement scrollIntoViewIfNeeded for firefox When we use firefox top or bottom arrow the ace container does not scroll automatically if the cursor is not visible. --- .../lib/ace/{ace.js => ace.odoo-custom.js} | 35 +++++++++++++++++++ .../web/static/src/js/views/form_widgets.js | 2 +- addons/website/static/src/js/website.ace.js | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) rename addons/web/static/lib/ace/{ace.js => ace.odoo-custom.js} (99%) diff --git a/addons/web/static/lib/ace/ace.js b/addons/web/static/lib/ace/ace.odoo-custom.js similarity index 99% rename from addons/web/static/lib/ace/ace.js rename to addons/web/static/lib/ace/ace.odoo-custom.js index 65a98e2a92a..628464abe25 100644 --- a/addons/web/static/lib/ace/ace.js +++ b/addons/web/static/lib/ace/ace.odoo-custom.js @@ -8204,6 +8204,41 @@ s *= this.session.$getStringScreenWidth(o)[0] + 2, i += 2 } n -= this.scrollLeft, n > this.$size.scrollerWidth - s && (n = this.$size.scrollerWidth - s), n += this.gutterWidth, r.height = i + "px", r.width = s + "px", r.left = Math.min(n, this.$size.scrollerWidth - s) + "px", r.top = Math.min(t, this.$size.height - i) + "px" + // ODOO monkeypatch: When we use firefox top or bottom arrow the ace container does not scroll automatically if the cursor is not visible. + this.$scrollViewToTextArea(); + }, this.$scrollViewToTextArea = function() { + // scroll the page/container to the cursor + var node = this.$cursorLayer.cursor; + setTimeout(function () { + if (node.scrollIntoViewIfNeeded) { + node.scrollIntoViewIfNeeded(false); + } else if (node.scrollIntoView) { + var rect = node.getBoundingClientRect(); + var parent = node.parentNode; + + while (parent && parent.getBoundingClientRect) { + var parentRect = parent.getBoundingClientRect(); + if (parentRect.bottom < rect.top) { + node.scrollIntoView(false); + return; + } + if (parentRect.top > rect.bottom-rect.height) { + node.scrollIntoView(true); + return; + } + if (parentRect.left > rect.right) { + node.scrollIntoView(); + return; + } + if (parentRect.right < rect.left) { + node.scrollIntoView(); + return; + } + parent = parent.parentNode; + } + } + }); + // ODOO end monkeypatch }, this.getFirstVisibleRow = function() { return this.layerConfig.firstRow }, this.getFirstFullyVisibleRow = function() { diff --git a/addons/web/static/src/js/views/form_widgets.js b/addons/web/static/src/js/views/form_widgets.js index 334f0db758c..6f9b8e3e2d7 100644 --- a/addons/web/static/src/js/views/form_widgets.js +++ b/addons/web/static/src/js/views/form_widgets.js @@ -1588,7 +1588,7 @@ var AceEditor = common.AbstractField.extend(common.ReinitializeFieldMixin, { template: "AceEditor", willStart: function() { if (!window.ace && !this.loadJS_def) { - this.loadJS_def = ajax.loadJS('/web/static/lib/ace/ace.js').then(function () { + this.loadJS_def = ajax.loadJS('/web/static/lib/ace/ace.odoo-custom.js').then(function () { return $.when(ajax.loadJS('/web/static/lib/ace/mode-python.js'), ajax.loadJS('/web/static/lib/ace/mode-xml.js'), ajax.loadJS('/web/static/lib/ace/theme-monokai.js')); diff --git a/addons/website/static/src/js/website.ace.js b/addons/website/static/src/js/website.ace.js index 11c439b6dfc..31717241a9d 100644 --- a/addons/website/static/src/js/website.ace.js +++ b/addons/website/static/src/js/website.ace.js @@ -23,7 +23,7 @@ var Ace = Widget.extend({ launchAce: function (e) { var self = this; if (!window.ace && !this.loadJS_def) { - this.loadJS_def = ajax.loadJS('/web/static/lib/ace/ace.js').then(function () { + this.loadJS_def = ajax.loadJS('/web/static/lib/ace/ace.odoo-custom.js').then(function () { return $.when(ajax.loadJS('/web/static/lib/ace/mode-xml.js'), ajax.loadJS('/web/static/lib/ace/theme-monokai.js')); });