From c77fd9285e34efcda175cc201613b0c3c5cba53b Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Mon, 12 Jun 2023 06:33:41 +0000 Subject: [PATCH] [FIX] web: CodeEditor: restore scrollability Before this commit, the CodeEditor made Ace display infinity lines in height. This prevented Ace to be scrollable in some contexts. Specifically, when Ace was in a flex context, the scroll did not work. After this commit, the CodeEditor takes an optional maxLines props to pass to Ace. If not set, Ace will just adapt the number of lines to the size it gets. closes odoo/odoo#124656 X-original-commit: eb81a4c857a249e4cd2f28b455d87b64a8e93c9a Related: odoo/enterprise#42367 Signed-off-by: Lucas Perais (lpe) --- addons/web/static/src/core/code_editor/code_editor.js | 3 ++- addons/web/static/src/views/fields/ace/ace_field.xml | 1 + addons/web/static/tests/core/code_editor_tests.js | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/core/code_editor/code_editor.js b/addons/web/static/src/core/code_editor/code_editor.js index d7d62731dbc..dd561247335 100644 --- a/addons/web/static/src/core/code_editor/code_editor.js +++ b/addons/web/static/src/core/code_editor/code_editor.js @@ -40,6 +40,7 @@ export class CodeEditor extends Component { optional: true, validate: (theme) => CodeEditor.THEMES.includes(theme), }, + maxLines: { type: Number, optional: true }, }; static defaultProps = { readonly: false, @@ -68,7 +69,7 @@ export class CodeEditor extends Component { this.aceEditor = aceEditor; this.aceEditor.setOptions({ - maxLines: Infinity, + maxLines: this.props.maxLines, showPrintMargin: false, }); this.aceEditor.session.setOptions({ diff --git a/addons/web/static/src/views/fields/ace/ace_field.xml b/addons/web/static/src/views/fields/ace/ace_field.xml index 492c9690b25..f86d50c153b 100644 --- a/addons/web/static/src/views/fields/ace/ace_field.xml +++ b/addons/web/static/src/views/fields/ace/ace_field.xml @@ -11,6 +11,7 @@ onChange.bind="handleChange" class="'ace-view-editor'" theme="theme" + maxLines="200" /> diff --git a/addons/web/static/tests/core/code_editor_tests.js b/addons/web/static/tests/core/code_editor_tests.js index 61f409622c6..b4928ca5bce 100644 --- a/addons/web/static/tests/core/code_editor_tests.js +++ b/addons/web/static/tests/core/code_editor_tests.js @@ -99,6 +99,7 @@ QUnit.module("Web Components", (hooks) => { mode="'xml'" value="state.value" onChange.bind="onChange" + maxLines="200" /> `; setup() {