File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ function onPaste(event: ClipboardEvent) {
2222
2323 const selectedText = field . value . substring ( field . selectionStart , field . selectionEnd )
2424 if ( ! selectedText . length ) return
25+ // Prevent linkification when replacing an URL
26+ // Trim whitespace in case whitespace is selected by mistake or by intention
27+ if ( isURL ( selectedText . trim ( ) ) ) return
2528
2629 event . stopPropagation ( )
2730 event . preventDefault ( )
Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ describe('paste-markdown', function () {
3131 assert . equal ( textarea . value , 'The examples can be found [here](https://github.com).' )
3232 } )
3333
34+ it ( 'turns pasted urls on selected urls not into markdown links' , function ( ) {
35+ // eslint-disable-next-line i18n-text/no-en
36+ textarea . value = 'The examples can be found here: https://docs.github.com'
37+ textarea . setSelectionRange ( 32 , 55 )
38+ paste ( textarea , { 'text/plain' : 'https://github.com' } )
39+ // Synthetic paste events don't manipulate the DOM. The same textarea value
40+ // means that the event handler didn't fire and normal paste happened.
41+ assert . equal ( textarea . value , 'The examples can be found here: https://docs.github.com' )
42+ } )
43+
3444 it ( 'turns html tables into markdown' , function ( ) {
3545 const data = {
3646 'text/html' : `
You can’t perform that action at this time.
0 commit comments