FIX: Use selected text in the link if text is already selected, otherwise, put the URL

This commit is contained in:
cpradio 2015-11-07 07:33:24 -05:00
parent ffa523a543
commit 8f39f25cad
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"');