From 44a5c29d427065efd19687c7c4cc644dfdd1209f Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Wed, 25 Jul 2018 09:12:49 +0200 Subject: [PATCH] Clear old text and URL when showing up the "Insert Hyperink" modal. (#6138) --- .../javascripts/discourse/components/d-editor.js.es6 | 6 +++--- test/javascripts/components/d-editor-test.js.es6 | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index d3d4c8ba01..1293d032d4 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -874,6 +874,9 @@ export default Ember.Component.extend({ return; } + this.set("linkUrl", ""); + this.set("linkText", ""); + this._lastSel = this._getSelected(); if (this._lastSel) { @@ -947,9 +950,6 @@ export default Ember.Component.extend({ this._selectText(sel.start + 1, origLink.length); } } - - this.set("linkUrl", ""); - this.set("linkText", ""); }, emoji() { diff --git a/test/javascripts/components/d-editor-test.js.es6 b/test/javascripts/components/d-editor-test.js.es6 index 4bf18bca96..58e4f88b30 100644 --- a/test/javascripts/components/d-editor-test.js.es6 +++ b/test/javascripts/components/d-editor-test.js.es6 @@ -241,6 +241,17 @@ testCase("link modal (cancel)", function(assert) { }); }); +testCase("link modal (cancel clears inputs)", async function(assert) { + await click("button.link"); + await fillIn(".insert-link input.link-url", "https://meta.discourse.org/"); + await fillIn(".insert-link input.link-text", "Discourse Meta"); + await click(".insert-link button.btn-danger"); + + await click("button.link"); + assert.equal(this.$(".insert-link input.link-url")[0].value, ""); + assert.equal(this.$(".insert-link input.link-text")[0].value, ""); +}); + testCase("link modal (simple link)", function(assert, textarea) { click("button.link");