From ec201d22059a347ccabedff69a7ef7e19197cfce Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Thu, 22 Dec 2022 13:08:14 +0000 Subject: [PATCH] [FIX] web: save ace field with alt+s Before this commit, edit an ace field and press alt+s remove the change. How: - edit an ace field - press alt+s Before: The change is removed. After: The change is saved. closes odoo/odoo#108579 X-original-commit: 5ca1b68ef9f5b31416cdfbeee6e984ca754d38cd Signed-off-by: Aaron Bohy (aab) --- .../static/src/views/fields/ace/ace_field.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/views/fields/ace/ace_field.js b/addons/web/static/src/views/fields/ace/ace_field.js index 44fdffa4789..9b3afdd5544 100644 --- a/addons/web/static/src/views/fields/ace/ace_field.js +++ b/addons/web/static/src/views/fields/ace/ace_field.js @@ -4,7 +4,7 @@ import { loadJS } from "@web/core/assets"; import { _lt } from "@web/core/l10n/translation"; import { registry } from "@web/core/registry"; -import { useService } from '@web/core/utils/hooks'; +import { useBus, useService } from "@web/core/utils/hooks"; import { formatText } from "../formatters"; import { standardFieldProps } from "../standard_field_props"; @@ -14,7 +14,7 @@ export class AceField extends Component { setup() { this.aceEditor = null; this.editorRef = useRef("editor"); - this.cookies = useService('cookie'); + this.cookies = useService("cookie"); onWillStart(async () => { await loadJS("/web/static/lib/ace/ace.js"); @@ -37,6 +37,11 @@ export class AceField extends Component { }, () => [this.editorRef.el] ); + + useBus(this.env.bus, "RELATIONAL_MODEL:WILL_SAVE_URGENTLY", () => this.commitChanges()); + useBus(this.env.bus, "RELATIONAL_MODEL:NEED_LOCAL_CHANGES", ({ detail }) => + detail.proms.push(this.commitChanges()) + ); } get aceSession() { @@ -48,7 +53,7 @@ export class AceField extends Component { this.aceEditor.setOptions({ maxLines: Infinity, showPrintMargin: false, - theme: (this.cookies.current.color_scheme === "dark" ? 'ace/theme/monokai' : ''), + theme: this.cookies.current.color_scheme === "dark" ? "ace/theme/monokai" : "", }); this.aceEditor.$blockScrolling = true; @@ -58,7 +63,7 @@ export class AceField extends Component { useSoftTabs: true, }); - this.aceEditor.on("blur", this.onBlur.bind(this)); + this.aceEditor.on("blur", this.commitChanges.bind(this)); } updateAce({ mode, readonly, value }) { @@ -95,9 +100,12 @@ export class AceField extends Component { } } - onBlur() { + commitChanges() { if (!this.props.readonly) { - this.props.update(this.aceSession.getValue()); + const value = this.aceSession.getValue(); + if (this.props.value !== value) { + return this.props.update(value); + } } } }