[Libreoffice-commits] online.git: loleaflet/src

Grzegorz Araminowicz (via logerrit) logerrit at kemper.freedesktop.org
Mon Nov 11 17:40:09 UTC 2019


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

New commits:
commit d10257cf0979eb076d3d942d35dbe55fdecb70d6
Author:     Grzegorz Araminowicz <grzegorz.araminowicz at collabora.com>
AuthorDate: Fri Nov 8 22:17:16 2019 +0100
Commit:     Grzegorz Araminowicz <grzegorz.araminowicz at 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.araminowicz at collabora.com>
    Tested-by: Grzegorz Araminowicz <grzegorz.araminowicz at 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') }),


More information about the Libreoffice-commits mailing list