[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) <aab@odoo.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user