Better behavior When inserting a link with no description
This commit is contained in:
parent
bb76c389fd
commit
8dc0fa97d4
|
@ -407,16 +407,22 @@ export default Ember.Component.extend({
|
|||
|
||||
insertLink() {
|
||||
const link = this.get('link');
|
||||
const sel = this._lastSel;
|
||||
|
||||
if (Ember.isEmpty(link)) { return; }
|
||||
const m = / "([^"]+)"/.exec(link);
|
||||
if (m && m.length === 2) {
|
||||
const description = m[1];
|
||||
const remaining = link.replace(m[0], '');
|
||||
this._addText(this._lastSel, `[${description}](${remaining})`);
|
||||
this._addText(sel, `[${description}](${remaining})`);
|
||||
} else {
|
||||
const selectedValue = this._lastSel.value || link;
|
||||
this._addText(this._lastSel, `[${selectedValue}](${link})`);
|
||||
if (sel.value) {
|
||||
this._addText(sel, `[${sel.value}](${link})`);
|
||||
} else {
|
||||
const desc = I18n.t('composer.link_description');
|
||||
this._addText(sel, `[${desc}](${link})`);
|
||||
this._selectText(sel.start + 1, desc.length);
|
||||
}
|
||||
}
|
||||
|
||||
this.set('link', '');
|
||||
|
|
|
@ -183,13 +183,16 @@ testCase('link modal (cancel)', function(assert) {
|
|||
});
|
||||
});
|
||||
|
||||
testCase('link modal (simple link)', function(assert) {
|
||||
testCase('link modal (simple link)', function(assert, textarea) {
|
||||
click('button.link');
|
||||
fillIn('.insert-link input', 'http://eviltrout.com');
|
||||
click('.insert-link button.btn-primary');
|
||||
const desc = I18n.t('composer.link_description');
|
||||
andThen(() => {
|
||||
assert.equal(this.$('.insert-link.hidden').length, 1);
|
||||
assert.equal(this.get('value'), 'hello world.[http://eviltrout.com](http://eviltrout.com)');
|
||||
assert.equal(this.get('value'), `hello world.[${desc}](http://eviltrout.com)`);
|
||||
assert.equal(textarea.selectionStart, 13);
|
||||
assert.equal(textarea.selectionEnd, 13 + desc.length);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue