11import { 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' ;
36import { Format } from '../../core/src/Format' ;
47import { 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
614export 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