loleaflet/src/control/Toolbar.js |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

New commits:
commit d10257cf0979eb076d3d942d35dbe55fdecb70d6
Author:     Grzegorz Araminowicz <grzegorz.araminow...@collabora.com>
AuthorDate: Fri Nov 8 22:17:16 2019 +0100
Commit:     Grzegorz Araminowicz <grzegorz.araminow...@collabora.com>
CommitDate: Mon Nov 11 18:39:51 2019 +0100

    Pre-populate hyperlink dialog text field with selected text
    
    using existing textselectioncontent message
    
    Change-Id: I64ad932e8462d2318532bb5b9899b5e546831e32
    Reviewed-on: https://gerrit.libreoffice.org/82334
    Reviewed-by: Grzegorz Araminowicz <grzegorz.araminow...@collabora.com>
    Tested-by: Grzegorz Araminowicz <grzegorz.araminow...@collabora.com>

diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 8c9ee5750..45770d65e 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -404,14 +404,28 @@ L.Map.include({
                });
        },
 
+       extractContent: function(html) {
+               var parser = new DOMParser;
+               return parser.parseFromString(html, 
'text/html').documentElement.getElementsByTagName('body')[0].textContent;
+       },
+
        showHyperlinkDialog: function() {
                var map = this;
+               var text = '';
+               var link = '';
+               if (this.hyperlinkUnderCursor && this.hyperlinkUnderCursor.text 
&& this.hyperlinkUnderCursor.link) {
+                       text = this.hyperlinkUnderCursor.text;
+                       link = this.hyperlinkUnderCursor.link;
+               } else if (this._clip._selectionType == 'text') {
+                       text = 
this.extractContent(this._clip._selectionContent);
+               }
+
                vex.dialog.open({
                        contentClassName: 'hyperlink-dialog',
                        message: _('Insert hyperlink'),
                        input: [
-                               _('Text') + '<input name="text" type="text" 
value="' + (map.hyperlinkUnderCursor.text || '') + '"/>',
-                               _('Link') + '<input name="link" type="text" 
value="' + (map.hyperlinkUnderCursor.link || '') + '"/>'
+                               _('Text') + '<input name="text" type="text" 
value="' + text + '"/>',
+                               _('Link') + '<input name="link" type="text" 
value="' + link + '"/>'
                        ].join(''),
                        buttons: [
                                $.extend({}, vex.dialog.buttons.YES, { text: 
_('OK') }),
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to