Fossil SCM

Improved link edit button to pre-fill the link URL if the currently selected text contains one.

vor0nwe 2018-10-19 17:55 vor0nwe-wiki-wysiwyg
Commit deea3ab9b5d5a22ffd13763d10cb64692bf0c57ca39e5a03b0d4804c3207c6f7
1 file changed +18 -4
+18 -4
--- src/wysiwyg.c
+++ src/wysiwyg.c
@@ -243,22 +243,36 @@
243243
@
244244
@ function handleFormatButton() {
245245
@ var extra;
246246
@ switch (this.dataset.format) {
247247
@ 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;
252252
@ }
253253
@ break;
254254
@ case 'formatblock':
255255
@ extra = 'blockquote';
256256
@ break;
257257
@ }
258258
@ formatDoc(this.dataset.format, extra);
259259
@ }
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
+ @
260274
@ }
261275
@
262276
@ /* Return true if the document editor is in WYSIWYG mode. Return
263277
@ ** false if it is in Markup mode */
264278
@ function isWysiwyg() {
265279
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button