File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
extension/src/json-viewer Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -89,15 +89,26 @@ Highlighter.prototype = {
8989 if ( text . match ( URL_PATTERN ) && self . clickableUrls ( ) ) {
9090 var decodedText = self . decodeText ( text ) ;
9191 elements . forEach ( function ( node ) {
92- node . classList . add ( "cm-string-link" ) ;
93- node . setAttribute ( "data-url" , decodedText ) ;
9492 if ( self . wrapLinkWithAnchorTag ( ) ) {
9593 var linkTag = document . createElement ( "a" ) ;
9694 linkTag . href = decodedText ;
9795 linkTag . setAttribute ( 'target' , '_blank' )
98- linkTag . innerHTML = decodedText ;
99- node . innerHTML = "" ;
96+ linkTag . classList . add ( "cm-string" ) ;
97+
98+ // reparent the child nodes to preserve the cursor when editing
99+ node . childNodes . forEach ( function ( child ) {
100+ linkTag . appendChild ( child ) ;
101+ } ) ;
102+
103+ // block CodeMirror's contextmenu handler
104+ linkTag . addEventListener ( "contextmenu" , function ( e ) {
105+ if ( e . bubbles ) e . cancelBubble = true ;
106+ } ) ;
107+
100108 node . appendChild ( linkTag ) ;
109+ } else {
110+ node . classList . add ( "cm-string-link" ) ;
111+ node . setAttribute ( "data-url" , decodedText ) ;
101112 }
102113 } ) ;
103114 }
You can’t perform that action at this time.
0 commit comments