Merge pull request #3891 from cpradio/fix-selected-link-text

FIX: Use selected text in the link if text is already selected, otherwise, put the URL
This commit is contained in:
Robin Ward 2015-11-09 16:24:07 -05:00
commit a7d87d1530
2 changed files with 15 additions and 1 deletions

View File

@ -404,7 +404,8 @@ export default Ember.Component.extend({
const remaining = link.replace(m[0], '');
this._addText(this._lastSel, `[${description}](${remaining})`);
} else {
this._addText(this._lastSel, `[${link}](${link})`);
const selectedValue = this._lastSel.value || link;
this._addText(this._lastSel, `[${selectedValue}](${link})`);
}
this.set('link', '');

View File

@ -193,6 +193,19 @@ testCase('link modal (simple link)', function(assert) {
});
});
testCase('link modal (simple link) with selected text', function(assert, textarea) {
textarea.selectionStart = 0;
textarea.selectionEnd = 12;
click('button.link');
fillIn('.insert-link input', 'http://eviltrout.com');
click('.insert-link button.btn-primary');
andThen(() => {
assert.equal(this.$('.insert-link.hidden').length, 1);
assert.equal(this.get('value'), '[hello world.](http://eviltrout.com)');
});
});
testCase('link modal (link with description)', function(assert) {
click('button.link');
fillIn('.insert-link input', 'http://eviltrout.com "evil trout"');