@@ -7,7 +7,9 @@ import type { EditorView } from '@tiptap/pm/view';
77import LinkEditPopover from '@/extensions/Link/components/LinkEditPopover' ;
88import type { GeneralOptions } from '@/types' ;
99
10- export interface LinkOptions extends TiptapLinkOptions , GeneralOptions < LinkOptions > { }
10+ export interface LinkOptions
11+ extends TiptapLinkOptions ,
12+ GeneralOptions < LinkOptions > { }
1113
1214export const Link = /* @__PURE__ */ TiptapLink . extend < LinkOptions > ( {
1315 inclusive : false ,
@@ -39,6 +41,12 @@ export const Link = /* @__PURE__ */ TiptapLink.extend<LinkOptions>({
3941 editor,
4042 action : ( value ) => {
4143 const { link, text, openInNewTab } = value ;
44+
45+ const { state } = editor ;
46+ const { from } = state . selection ;
47+ const insertedLength = text . length ;
48+ const to = from + insertedLength ;
49+
4250 editor
4351 . chain ( )
4452 . extendMarkRange ( 'link' )
@@ -56,6 +64,7 @@ export const Link = /* @__PURE__ */ TiptapLink.extend<LinkOptions>({
5664 ] ,
5765 } )
5866 . setLink ( { href : link } )
67+ . setTextSelection ( { from, to } ) // 👈 Select inserted text
5968 . focus ( )
6069 . run ( ) ;
6170 } ,
@@ -82,7 +91,9 @@ export const Link = /* @__PURE__ */ TiptapLink.extend<LinkOptions>({
8291 }
8392 const $start = doc . resolve ( range . from ) ;
8493 const $end = doc . resolve ( range . to ) ;
85- const transaction = tr . setSelection ( new TextSelection ( $start , $end ) ) ;
94+ const transaction = tr . setSelection (
95+ new TextSelection ( $start , $end )
96+ ) ;
8697 view . dispatch ( transaction ) ;
8798 } ,
8899 } ,
0 commit comments