diff --git a/app/javascript/controllers/wiki_toolbar_controller.js b/app/javascript/controllers/wiki_toolbar_controller.js index 8f92b8a..413641e 100644 --- a/app/javascript/controllers/wiki_toolbar_controller.js +++ b/app/javascript/controllers/wiki_toolbar_controller.js @@ -32,7 +32,8 @@ export default class extends Controller { if (!this.field) return if (!this.editorTarget.contains(this.field)) { - // Moving the element reconnects the controller + // Moving the element removes the focus and reconnects the controller + this.focusField = document.activeElement === this.field this.field.before(this.element) this.editorTarget.prepend(this.field) } @@ -41,6 +42,8 @@ export default class extends Controller { .catch((error) => console.error(`Wiki toolbar syntax not found for ${this.formatValue}`, error)) this.addShortcutsToTitles() this.element.hidden = false + if (this.focusField) this.field.focus() + this.focusField = false } disconnect() {