File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
packages/core/src/extensions/LinkToolbar Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -79,23 +79,38 @@ export const LinkToolbarExtension = createExtension(({ editor }) => {
7979 ) {
8080 editor . transact ( ( tr ) => {
8181 const pmSchema = getPmSchema ( tr ) ;
82- const { range } = getMarkAtPos ( position + 1 , "link" ) || {
82+
83+ const linkInfo = getMarkAtPos ( position + 1 , "link" ) || {
8384 range : {
8485 from : tr . selection . from ,
8586 to : tr . selection . to ,
8687 } ,
8788 } ;
89+
90+ const { range } = linkInfo ;
91+
8892 if ( ! range ) {
8993 return ;
9094 }
95+ const existingMarks =
96+ tr . doc . nodeAt ( Math . max ( range . from , range . to - 1 ) ) ?. marks ?? [ ] ;
97+
9198 tr . insertText ( text , range . from , range . to ) ;
99+
100+ for ( const existingMark of existingMarks ) {
101+ if ( existingMark . type . name !== "link" ) {
102+ tr . addMark ( range . from , range . from + text . length , existingMark ) ;
103+ }
104+ }
105+
92106 tr . addMark (
93107 range . from ,
94108 range . from + text . length ,
95109 pmSchema . mark ( "link" , { href : url } ) ,
96110 ) ;
97- } ) ;
98- editor . prosemirrorView . focus ( ) ;
111+ } ) ;
112+
113+ editor . prosemirrorView . focus ( ) ;
99114 } ,
100115 deleteLink ( position = editor . transact ( ( tr ) => tr . selection . anchor ) ) {
101116 editor . transact ( ( tr ) => {
You can’t perform that action at this time.
0 commit comments