@@ -37,7 +37,23 @@ export class UrlTextHandler {
3737 this . _element = element ;
3838 this . _copyButton = copyButton ;
3939 this . _userIndex = - 1 ;
40+ this . _completedUrl = "" ;
4041
42+ // Only encode the URL if the entire text is selected.
43+ if ( this . _element ) {
44+ this . _element . addEventListener ( "copy" , ( event ) => {
45+ const selectedText = window . getSelection ( ) ?. toString ( ) ;
46+ const totalText = this . _element . value ;
47+
48+ // Check if the selected text length matches the total text length.
49+ if ( event . clipboardData && selectedText && selectedText . length === totalText . length ) {
50+ event . preventDefault ( ) ;
51+ event . clipboardData . setData ( "text/plain" , this . _completedUrl || "" ) ;
52+ }
53+ // Allow default copying if only a part of the text is selected.
54+ } ) ;
55+ }
56+
4157 this . _element . addEventListener ( "focusin" , ( ) => {
4258 this . _element . setSelectionRange ( 0 , 99999 ) ;
4359 this . _updateScroll ( ) ;
@@ -88,7 +104,7 @@ export class UrlTextHandler {
88104 _oncopy ( ) {
89105 if ( ! this . _element . value ) return ;
90106
91- navigator . clipboard . writeText ( this . _element . value ) . then ( ( ) => {
107+ navigator . clipboard . writeText ( this . _completedUrl || "" ) . then ( ( ) => {
92108 if ( this . _copyButton ) {
93109 this . _copyButton . classList . add ( "copied" ) ;
94110 this . _copyButton . title = "Copied!" ;
@@ -108,7 +124,8 @@ export class UrlTextHandler {
108124 * @param {string } href The href to set.
109125 */
110126 setHref ( href ) {
111- this . _element . value = completeHref ( href ) ;
127+ this . _completedUrl = completeHref ( href ) ;
128+ this . _element . value = decodeURIComponent ( this . _completedUrl ) ;
112129
113130 this . _update_username_index ( ) ;
114131 this . _updateScroll ( ) ;
0 commit comments