@@ -57,7 +57,7 @@ function getSelnRange(editor: Editor, settings: PluginSettings) {
57
57
} else {
58
58
switch ( settings . nothingSelected ) {
59
59
case NothingSelected . autoSelect :
60
- replaceRange = getWordBoundaries ( editor ) ;
60
+ replaceRange = getWordBoundaries ( editor , settings ) ;
61
61
selectedText = editor . getRange ( replaceRange . from , replaceRange . to ) ;
62
62
break ;
63
63
case NothingSelected . insertInline :
@@ -162,16 +162,20 @@ function getCbText(cb: string | ClipboardEvent): string | null {
162
162
return clipboardText . trim ( ) ;
163
163
}
164
164
165
- function getWordBoundaries ( editor : Editor ) : EditorRange {
165
+ function getWordBoundaries ( editor : Editor , settings : PluginSettings ) : EditorRange {
166
166
const cursor = editor . getCursor ( ) ;
167
- let wordBoundaries : EditorRange ;
168
-
169
- // if (editor.getTokenTypeAt(cursor) === "url") {
170
- // const { start: startCh, end: endCh } = editor.getTokenAt(cursor);
171
- // const line = cursor.line;
172
- // wordBoundaries = { from: { line, ch: startCh }, to: { line, ch: endCh } };
173
- // } else
174
- wordBoundaries = findWordAt ( editor . getLine ( cursor . ch ) , cursor ) ; ;
167
+ const line = editor . getLine ( cursor . line ) ;
168
+ let wordBoundaries = findWordAt ( line , cursor ) ; ;
169
+
170
+ // If the token the cursor is on is a url, grab the whole thing instead of just parsing it like a word
171
+ let start = wordBoundaries . from . ch ;
172
+ let end = wordBoundaries . to . ch ;
173
+ while ( start > 0 && ! / \s / . test ( line . charAt ( start - 1 ) ) ) -- start ;
174
+ while ( end < line . length && ! / \s / . test ( line . charAt ( end ) ) ) ++ end ;
175
+ if ( isUrl ( line . slice ( start , end ) , settings ) ) {
176
+ wordBoundaries . from . ch = start ;
177
+ wordBoundaries . to . ch = end ;
178
+ }
175
179
return wordBoundaries ;
176
180
}
177
181
@@ -189,7 +193,6 @@ const findWordAt = (() => {
189
193
let end = pos . ch ;
190
194
( end === line . length ) ? -- start : ++ end ;
191
195
const startChar = line . charAt ( pos . ch ) ;
192
-
193
196
if ( isWordChar ( startChar ) ) {
194
197
check = ( ch : string ) => isWordChar ( ch ) ;
195
198
} else if ( / \s / . test ( startChar ) ) {
0 commit comments