Focus the editor when title is pre-filled

Oh, I see. I assumed you used JS in its files.

From the admin UI, then, you would write:

<script type="text/discourse-plugin" version="1.8.0">
    const putCursorAtEnd = require("discourse/lib/put-cursor-at-end").default;
    const { scheduleOnce } = require("@ember/runloop");

    api.onAppEvent("composer:open", ({ model }) => {
      if (model.title !== "") {
        scheduleOnce("afterRender", () => {
          putCursorAtEnd(document.querySelector("textarea.d-editor-input"));
        });
      }
    });
</script>

On a side note, I highly encourage you to use the Theme CLI. You can create a theme component from a template, sync it with a Discourse with live refresh, and update any changes using your editor. It’s much easier than using the UI!

2 Likes