FIX: don't steal focus when text in editor is replaced (#6712)

This commit is contained in:
Maja Komel 2018-12-03 09:49:17 +01:00 committed by Régis Hanol
parent 503ae1829f
commit 142361d6da
2 changed files with 11 additions and 2 deletions

View File

@ -676,8 +676,13 @@ export default Ember.Component.extend({
// Replace value (side effect: cursor at the end).
this.set("value", val.replace(oldVal, newVal));
// Restore cursor.
this._selectText(newSelection.start, newSelection.end - newSelection.start);
if ($("textarea.d-editor-input").is(":focus")) {
// Restore cursor.
this._selectText(
newSelection.start,
newSelection.end - newSelection.start
);
}
},
_addBlock(sel, text) {

View File

@ -804,6 +804,10 @@ composerTestCase("replace-text event for composer", async function(assert) {
assert,
textarea
) {
const focusEvent = $.Event("focus");
const $input = $('textarea.d-editor-input');
$input.trigger(focusEvent);
this.set("value", BEFORE);
await setSelection(textarea, CASE.before);