# 在标题预填写时聚焦编辑器

**URL:** https://meta.discourse.org/t/focus-the-editor-when-title-is-pre-filled/311449
**Category:** Development
**Created:** [2024年六月10日 21:10 UTC](https://meta.discourse.org/t/focus-the-editor-when-title-is-pre-filled/311449 "2024-06-10T21:10:26Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [2024年六月11日 09:23 UTC](https://meta.discourse.org/t/focus-the-editor-when-title-is-pre-filled/311449/8 "2024-06-11T09:23:12Z")

</div>

哦，我明白了。我以为你在它的文件中使用了 JS [its files](https://meta.discourse.org/t/split-up-theme-javascript-into-multiple-files/119369)。

那么，从管理员界面，你会写：

```js
<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>

```

顺便说一句，我强烈建议你使用 [Theme CLI](https://meta.discourse.org/t/install-the-discourse-theme-cli-console-app-to-help-you-build-themes/82950)。你可以从模板创建一个主题组件，将其与 Discourse 同步并实时刷新，然后使用编辑器更新任何更改。这比使用 UI 容易得多！

---

_[View the full topic](https://meta.discourse.org/t/focus-the-editor-when-title-is-pre-filled/311449)._
