[FIX] web: AceField: reset ace lib only if editor's element has changed
Before this commit, the ace editor crashed when switching to edit mode or when clicking in it. After this commit, it works as expected. Part-of: odoo/odoo#78221
This commit is contained in:
committed by
Géry Debongnie
parent
b4063a1e73
commit
c0a67682cb
@@ -25,10 +25,13 @@ export class AceField extends Component {
|
||||
return Promise.all(proms);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
this.setupAce();
|
||||
return () => this.destroyAce();
|
||||
});
|
||||
useEffect(
|
||||
() => {
|
||||
this.setupAce();
|
||||
return () => this.destroyAce();
|
||||
},
|
||||
() => [this.editorRef.el]
|
||||
);
|
||||
}
|
||||
|
||||
get aceSession() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { getFixture } from "@web/../tests/helpers/utils";
|
||||
import { getFixture, clickEdit, triggerEvents } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
let serverData;
|
||||
@@ -57,4 +57,22 @@ QUnit.module("Fields", (hooks) => {
|
||||
|
||||
assert.ok(target.querySelector(".o_field_ace").textContent.includes("yop"));
|
||||
});
|
||||
|
||||
QUnit.test("AceEditorField doesn't crash when editing", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="display_name" />
|
||||
<field name="foo" widget="ace" />
|
||||
</form>`,
|
||||
});
|
||||
|
||||
await clickEdit(target);
|
||||
await triggerEvents(target, ".ace-view-editor textarea", ["focus", "click"]);
|
||||
assert.hasClass(target.querySelector(".ace-view-editor"), "ace_focus");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user