Fossil SCM
Improved link edit button to pre-fill the link URL if the currently selected text contains one.
Commit
deea3ab9b5d5a22ffd13763d10cb64692bf0c57ca39e5a03b0d4804c3207c6f7
Parent
bab6720aaa7868c…
1 file changed
+18
-4
+18
-4
| --- src/wysiwyg.c | ||
| +++ src/wysiwyg.c | ||
| @@ -243,22 +243,36 @@ | ||
| 243 | 243 | @ |
| 244 | 244 | @ function handleFormatButton() { |
| 245 | 245 | @ var extra; |
| 246 | 246 | @ switch (this.dataset.format) { |
| 247 | 247 | @ case 'createlink': |
| 248 | - @ var sLnk = prompt('Target URL:',''); | |
| 249 | - @ if(sLnk && sLnk != '') | |
| 250 | - @ { | |
| 251 | - @ extra = sLnk; | |
| 248 | + @ var url = getSelectedUrl(); | |
| 249 | + @ url = prompt('Target URL:', url ? url : ''); | |
| 250 | + @ if(url && url != '') { | |
| 251 | + @ extra = url; | |
| 252 | 252 | @ } |
| 253 | 253 | @ break; |
| 254 | 254 | @ case 'formatblock': |
| 255 | 255 | @ extra = 'blockquote'; |
| 256 | 256 | @ break; |
| 257 | 257 | @ } |
| 258 | 258 | @ formatDoc(this.dataset.format, extra); |
| 259 | 259 | @ } |
| 260 | + @ | |
| 261 | + @ function getSelectedUrl() { | |
| 262 | + @ if (!window.getSelection) return; | |
| 263 | + @ var sel = window.getSelection(); | |
| 264 | + @ if (!sel) return; | |
| 265 | + @ return getNodeUrl(sel.focusNode) || getNodeUrl(sel.anchorNode); | |
| 266 | + @ } | |
| 267 | + @ function getNodeUrl(node) { | |
| 268 | + @ while (node) { | |
| 269 | + @ if (node.nodeName === 'A') return node.href; | |
| 270 | + @ node = node.parentElement; | |
| 271 | + @ } | |
| 272 | + @ } | |
| 273 | + @ | |
| 260 | 274 | @ } |
| 261 | 275 | @ |
| 262 | 276 | @ /* Return true if the document editor is in WYSIWYG mode. Return |
| 263 | 277 | @ ** false if it is in Markup mode */ |
| 264 | 278 | @ function isWysiwyg() { |
| 265 | 279 |
| --- src/wysiwyg.c | |
| +++ src/wysiwyg.c | |
| @@ -243,22 +243,36 @@ | |
| 243 | @ |
| 244 | @ function handleFormatButton() { |
| 245 | @ var extra; |
| 246 | @ switch (this.dataset.format) { |
| 247 | @ case 'createlink': |
| 248 | @ var sLnk = prompt('Target URL:',''); |
| 249 | @ if(sLnk && sLnk != '') |
| 250 | @ { |
| 251 | @ extra = sLnk; |
| 252 | @ } |
| 253 | @ break; |
| 254 | @ case 'formatblock': |
| 255 | @ extra = 'blockquote'; |
| 256 | @ break; |
| 257 | @ } |
| 258 | @ formatDoc(this.dataset.format, extra); |
| 259 | @ } |
| 260 | @ } |
| 261 | @ |
| 262 | @ /* Return true if the document editor is in WYSIWYG mode. Return |
| 263 | @ ** false if it is in Markup mode */ |
| 264 | @ function isWysiwyg() { |
| 265 |
| --- src/wysiwyg.c | |
| +++ src/wysiwyg.c | |
| @@ -243,22 +243,36 @@ | |
| 243 | @ |
| 244 | @ function handleFormatButton() { |
| 245 | @ var extra; |
| 246 | @ switch (this.dataset.format) { |
| 247 | @ case 'createlink': |
| 248 | @ var url = getSelectedUrl(); |
| 249 | @ url = prompt('Target URL:', url ? url : ''); |
| 250 | @ if(url && url != '') { |
| 251 | @ extra = url; |
| 252 | @ } |
| 253 | @ break; |
| 254 | @ case 'formatblock': |
| 255 | @ extra = 'blockquote'; |
| 256 | @ break; |
| 257 | @ } |
| 258 | @ formatDoc(this.dataset.format, extra); |
| 259 | @ } |
| 260 | @ |
| 261 | @ function getSelectedUrl() { |
| 262 | @ if (!window.getSelection) return; |
| 263 | @ var sel = window.getSelection(); |
| 264 | @ if (!sel) return; |
| 265 | @ return getNodeUrl(sel.focusNode) || getNodeUrl(sel.anchorNode); |
| 266 | @ } |
| 267 | @ function getNodeUrl(node) { |
| 268 | @ while (node) { |
| 269 | @ if (node.nodeName === 'A') return node.href; |
| 270 | @ node = node.parentElement; |
| 271 | @ } |
| 272 | @ } |
| 273 | @ |
| 274 | @ } |
| 275 | @ |
| 276 | @ /* Return true if the document editor is in WYSIWYG mode. Return |
| 277 | @ ** false if it is in Markup mode */ |
| 278 | @ function isWysiwyg() { |
| 279 |