Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit f7beb24

Browse files
Gorashdmo-odoo
authored andcommitted
[FIX] Odoo: double clicking on a link allows you to edit it in full
1 parent 0bd9488 commit f7beb24

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

packages/plugin-odoo/src/LinkFormatDomObjectModifierRenderer.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { FormatDomObjectModifierRenderer } from '../../plugin-renderer-dom-object/src/FormatDomObjectModifierRenderer';
2-
import { DomObjectRenderingEngine, DomObject } from '../../plugin-renderer-dom-object/src/DomObjectRenderingEngine';
2+
import {
3+
DomObjectRenderingEngine,
4+
DomObject,
5+
} from '../../plugin-renderer-dom-object/src/DomObjectRenderingEngine';
36
import { Format } from '../../core/src/Format';
47
import { LinkFormat } from '../../plugin-link/src/LinkFormat';
8+
import { Layout } from '../../plugin-layout/src/Layout';
9+
import { DomLayoutEngine } from '../../plugin-dom-layout/src/DomLayoutEngine';
10+
import { Core } from '../../core/src/Core';
11+
import { Direction } from '../../core/src/VSelection';
12+
import { RelativePosition } from '../../core/src/VNodes/VNode';
513

614
export class LinkFormatDomObjectModifierRenderer extends FormatDomObjectModifierRenderer {
715
static id = DomObjectRenderingEngine.id;
@@ -15,12 +23,25 @@ export class LinkFormatDomObjectModifierRenderer extends FormatDomObjectModifier
1523
const domObjects = await super.render(format, contents);
1624
const link = domObjects[0];
1725
if ('tag' in link) {
18-
const dbclickCallback = (): void => {
19-
this.engine.editor.execCommand('openLinkDialog');
20-
};
21-
26+
let dbclickCallback: (ev: MouseEvent) => Promise<void>;
2227
const savedAttach = link.attach;
2328
link.attach = (el: HTMLElement): void => {
29+
dbclickCallback = async (ev: MouseEvent): Promise<void> => {
30+
ev.preventDefault();
31+
const layout = this.engine.editor.plugins.get(Layout);
32+
const domEngine = layout.engines.dom as DomLayoutEngine;
33+
const nodes = domEngine.getNodes(el);
34+
await this.engine.editor.execCommand<Core>('setSelection', {
35+
vSelection: {
36+
anchorNode: nodes[0],
37+
anchorPosition: RelativePosition.BEFORE,
38+
focusNode: nodes[nodes.length - 1],
39+
focusPosition: RelativePosition.AFTER,
40+
direction: Direction.FORWARD,
41+
},
42+
});
43+
this.engine.editor.execCommand('openLinkDialog');
44+
};
2445
if (savedAttach) {
2546
savedAttach(el);
2647
}

0 commit comments

Comments
 (0)