File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,15 @@ function onPaste(event: ClipboardEvent) {
1717
1818 const text = transfer . getData ( 'text/plain' )
1919 if ( ! text ) return
20-
20+ if ( ! isURL ( text ) ) return
2121 if ( isWithinLink ( field ) ) return
2222
23+ const selectedText = field . value . substring ( field . selectionStart , field . selectionEnd )
24+ if ( ! selectedText . length ) return
25+
2326 event . stopPropagation ( )
2427 event . preventDefault ( )
2528
26- const selectedText = field . value . substring ( field . selectionStart , field . selectionEnd )
27-
2829 insertText ( field , linkify ( selectedText , text ) )
2930}
3031
@@ -44,7 +45,7 @@ function isWithinLink(textarea: HTMLTextAreaElement): boolean {
4445}
4546
4647function linkify ( selectedText : string , text : string ) : string {
47- return selectedText . length && isURL ( text ) ? `[${ selectedText } ](${ text } )` : text
48+ return `[${ selectedText } ](${ text } )`
4849}
4950
5051function isURL ( url : string ) : boolean {
You can’t perform that action at this time.
0 commit comments