FIX: Update preview when autocomplete is clicked (PR #10430)

d-editor observes value changing, and should update the preview.

https://github.com/discourse/discourse/blob/ba3ee3444eb9bad94a8f612f4c3636d4985e57eb/app/assets/javascripts/discourse/app/components/d-editor.js#L390

This is happening when an autocomplete option is selected using the ENTER, but when you click an option, the value of the textarea is updated, but this observes does not pick up the change for some reason that I cannot see.

By manually resetting composer.reply (which is passed into d-editor here), the value in d-editor is set, and the observes catches the change, which updates the preview. It is not the slickest thing I’ve ever seen, but I can’t see why the textarea would be changing but the observes does not notice.

GitHub

@markvanlan I think that’s OK.

This is actually what we do for emojis: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/app/components/d-editor.js#L435 as “value” is actually “composer.reply” as you can find out here: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/app/templates/components/composer-editor.hbs#L3

Although you dont need the self = this and $input.val() something like this should do it:

        afterComplete: (value) => {
          this.composer.set("reply", value);

          // ensures textarea scroll position is correct
          schedule("afterRender", () => $input.blur().focus());
        },

cf my comment

using value instead of $input.val() didn’t work ?

@jjaffeux Too focused on self being removed, I missed the rest of your recommendation.