mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-25 07:54:11 -05:00
FIX: After uploading an image the selection was not in the correct spot
This commit is contained in:
parent
215eae9972
commit
3200d836f7
3 changed files with 29 additions and 6 deletions
|
@ -189,7 +189,7 @@ export default Ember.Component.extend({
|
||||||
this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false });
|
this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false });
|
||||||
}
|
}
|
||||||
if (removePlaceholder) {
|
if (removePlaceholder) {
|
||||||
this.set('composer.reply', this.get('composer.reply').replace(this.get('uploadPlaceholder'), ""));
|
this.appEvents.trigger('composer:replace-text', this.get('uploadPlaceholder'), "");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -219,7 +219,6 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
$element.on("fileuploadsend", (e, data) => {
|
$element.on("fileuploadsend", (e, data) => {
|
||||||
this._validUploads++;
|
this._validUploads++;
|
||||||
// add upload placeholders
|
|
||||||
this.appEvents.trigger('composer:insert-text', uploadPlaceholder);
|
this.appEvents.trigger('composer:insert-text', uploadPlaceholder);
|
||||||
|
|
||||||
if (data.xhr && data.originalFiles.length === 1) {
|
if (data.xhr && data.originalFiles.length === 1) {
|
||||||
|
@ -244,7 +243,7 @@ export default Ember.Component.extend({
|
||||||
if (upload && upload.url) {
|
if (upload && upload.url) {
|
||||||
if (!this._xhr || !this._xhr._userCancelled) {
|
if (!this._xhr || !this._xhr._userCancelled) {
|
||||||
const markdown = getUploadMarkdown(upload);
|
const markdown = getUploadMarkdown(upload);
|
||||||
this.set('composer.reply', this.get('composer.reply').replace(uploadPlaceholder, markdown));
|
this.appEvents.trigger('composer:replace-text', uploadPlaceholder, markdown);
|
||||||
this._resetUpload(false);
|
this._resetUpload(false);
|
||||||
} else {
|
} else {
|
||||||
this._resetUpload(true);
|
this._resetUpload(true);
|
||||||
|
|
|
@ -215,9 +215,8 @@ export default Ember.Component.extend({
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appEvents.on('composer:insert-text', text => {
|
this.appEvents.on('composer:insert-text', text => this._addText(this._getSelected(), text));
|
||||||
this._addText(this._getSelected(), text);
|
this.appEvents.on('composer:replace-text', (oldVal, newVal) => this._replaceText(oldVal, newVal));
|
||||||
});
|
|
||||||
|
|
||||||
this._mouseTrap = mouseTrap;
|
this._mouseTrap = mouseTrap;
|
||||||
},
|
},
|
||||||
|
@ -225,6 +224,7 @@ export default Ember.Component.extend({
|
||||||
@on('willDestroyElement')
|
@on('willDestroyElement')
|
||||||
_shutDown() {
|
_shutDown() {
|
||||||
this.appEvents.off('composer:insert-text');
|
this.appEvents.off('composer:insert-text');
|
||||||
|
this.appEvents.off('composer:replace-text');
|
||||||
|
|
||||||
const mouseTrap = this._mouseTrap;
|
const mouseTrap = this._mouseTrap;
|
||||||
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
|
||||||
|
@ -475,6 +475,15 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_replaceText(oldVal, newVal) {
|
||||||
|
const val = this.get('value');
|
||||||
|
const loc = val.indexOf(oldVal);
|
||||||
|
if (loc !== -1) {
|
||||||
|
this.set('value', val.replace(oldVal, newVal));
|
||||||
|
this._selectText(loc + newVal.length, 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_addText(sel, text) {
|
_addText(sel, text) {
|
||||||
const $textarea = this.$('textarea.d-editor-input');
|
const $textarea = this.$('textarea.d-editor-input');
|
||||||
const insert = `${sel.pre}${text}`;
|
const insert = `${sel.pre}${text}`;
|
||||||
|
|
|
@ -596,3 +596,18 @@ componentTest('emoji', {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testCase("replace-text event", function(assert, textarea) {
|
||||||
|
|
||||||
|
this.set('value', "red green blue");
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
this.container.lookup('app-events:main').trigger('composer:replace-text', 'green', 'yellow');
|
||||||
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(this.get('value'), 'red yellow blue');
|
||||||
|
assert.equal(textarea.selectionStart, 10);
|
||||||
|
assert.equal(textarea.selectionEnd, 10);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue