From: Jan Szejko Date: Thu, 11 Jan 2018 14:24:11 +0000 (+0100) Subject: auto fill url when obvious X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/7411943f320a29c7b2bf7086a26a0a477eea68cc?ds=inline auto fill url when obvious --- diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 3839a39..6dce4ef 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -522,13 +522,21 @@ var createWrapTextAction = function(createParams) { var createLinkFromSelection = function(callback, params) { - var doc = params.fragment.document, - dialog = Dialog.create({ + var fragment = params.fragment, + doc = fragment.document, + text = fragment.startNode.nativeNode.data.substring(fragment.startOffset, fragment.endOffset), + url; + if (text.indexOf('//') >= 0 && text.indexOf(' ') < 0) { + url = text; + } else if (text.substr(0, 4) === 'www.' && text.indexOF(' ') < 0) { + url = 'http://' + text; + } + var dialog = Dialog.create({ title: gettext('Create link'), executeButtonText: gettext('Apply'), cancelButtonText: gettext('Cancel'), fields: [ - {label: gettext('Link'), name: 'href', type: 'input', + {label: gettext('Link'), name: 'href', type: 'input', initialValue: url || '', prePasteHandler: function(text) { return params.fragment.document.getLinkForUrl(text); }.bind(this)