Debian Codegraph @

addons/html_editor/static/tests/tours/helpers/editor.js

raw
1 import { patch } from "@web/core/utils/patch";
2
3 // To expose the editor instance globally for tour.
4 export const editorsWeakMap = new WeakMap();
5
6 const editorModule = odoo.loader.modules.get("@html_editor/editor");
7 if (editorModule) {
8 const { Editor } = editorModule;
9 patch(Editor.prototype, {
10 attachTo(editable) {
11 editorsWeakMap.set(editable.ownerDocument, this);
12 return super.attachTo(...arguments);
13 },
14 });
15 }
16
17 export function setSelection({
18 anchorNode,
19 anchorOffset,
20 focusNode = anchorNode,
21 focusOffset = anchorOffset,
22 }) {
23 const selection = anchorNode.ownerDocument.getSelection();
24 selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
25 }