From a01218d0c5733b1c979c6dca8bc388e7da5b0c01 Mon Sep 17 00:00:00 2001 From: "s.sisti@elogic.it" Date: Tue, 3 Nov 2026 10:42:00 +0100 Subject: [PATCH 1/4] FIX: Initialise rich editor state in wizard composer The wizard composer always forced the textarea editor, and when the rich_editor site setting is enabled isRichEditorEnabled started out undefined, so users had to click the MD/rich toggle twice to reach the rich text view. Initialise it from the site setting, defer to core setupEditorMode and only swap in CustomWizardTextareaEditor in markdown mode so the wizard text bindings keep working. Co-Authored-By: Claude Opus 5.5 --- .../initializers/custom-wizard-edits.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js b/assets/javascripts/discourse/initializers/custom-wizard-edits.js index f944fe777..ec8e26e4b 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js @@ -47,8 +47,24 @@ export default { setupEditorMode() { if (this.wizardComposer) { - this.editorComponent = CustomWizardTextareaEditor; - return; + // Without an explicit initial value the MD/rich toggle starts in + // an undefined state and needs two clicks to reach the rich editor. + if ( + this.isRichEditorEnabled === undefined || + this.isRichEditorEnabled === null + ) { + this.isRichEditorEnabled = !!this.siteSettings?.rich_editor; + } + + const result = this._super(...arguments); + + // Keep the wizard textarea editor in markdown mode so the + // wizard insert/replace text bindings keep working. + if (!this.isRichEditorEnabled) { + this.editorComponent = CustomWizardTextareaEditor; + } + + return result; } return this._super(...arguments); }, From e23316d97d9579364e132cd4f8eed875688b1fb7 Mon Sep 17 00:00:00 2001 From: "s.sisti@elogic.it" Date: Tue, 3 Nov 2026 11:07:02 +0100 Subject: [PATCH 2/4] Bump version Co-Authored-By: Claude Opus 5.5 --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index b113e3548..4c00af195 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.18.6 +# version: 2.18.7 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Marcos Gutierrez # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 80df9b70e89dffbd7b6a7009cf4d1b146c010f22 Mon Sep 17 00:00:00 2001 From: "s.sisti@elogic.it" Date: Tue, 3 Nov 2026 11:20:45 +0100 Subject: [PATCH 3/4] Fix the editor toggle state instead of changing the default mode Core derives isRichEditorEnabled from editorComponent and only treats its own TextareaEditor as markdown, so the wizard textarea editor made the toggle start in the rich state. Override the getter and keep the wizard textarea editor when toggling back to markdown. The wizard composer keeps defaulting to markdown, and core setupEditorMode (which assumes a logged in user) is no longer called. Co-Authored-By: Claude Opus 5.5 --- .../initializers/custom-wizard-edits.js | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js b/assets/javascripts/discourse/initializers/custom-wizard-edits.js index ec8e26e4b..92e19a333 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js @@ -1,4 +1,5 @@ import { action } from "@ember/object"; +import TextareaEditor from "discourse/components/composer/textarea-editor"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import getUrl from "discourse/lib/get-url"; @@ -42,29 +43,41 @@ export default { } ); + // Core treats any editor other than its own TextareaEditor as the rich + // editor, so the wizard textarea made the MD/rich toggle start in the + // wrong state and need two clicks to reach the rich editor. + api.modifyClass( + "component:d-editor", + (Superclass) => + class extends Superclass { + get isRichEditorEnabled() { + if (this.editorComponent === CustomWizardTextareaEditor) { + return false; + } + return super.isRichEditorEnabled; + } + + @action + async toggleRichEditor() { + await super.toggleRichEditor(...arguments); + + if ( + this.wizardComposer && + this.editorComponent === TextareaEditor + ) { + this.editorComponent = CustomWizardTextareaEditor; + } + } + } + ); + api.modifyClass("component:d-editor", { pluginId: "custom-wizard", setupEditorMode() { if (this.wizardComposer) { - // Without an explicit initial value the MD/rich toggle starts in - // an undefined state and needs two clicks to reach the rich editor. - if ( - this.isRichEditorEnabled === undefined || - this.isRichEditorEnabled === null - ) { - this.isRichEditorEnabled = !!this.siteSettings?.rich_editor; - } - - const result = this._super(...arguments); - - // Keep the wizard textarea editor in markdown mode so the - // wizard insert/replace text bindings keep working. - if (!this.isRichEditorEnabled) { - this.editorComponent = CustomWizardTextareaEditor; - } - - return result; + this.editorComponent = CustomWizardTextareaEditor; + return; } return this._super(...arguments); }, From 6abe691e379a0aecb767be33ef15b7227ef3a777 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 5 Nov 2026 16:40:05 +0700 Subject: [PATCH 4/4] DEV: Test the wizard composer editor toggle Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DSz8MWGMF9Utk4gyCsBEcw --- test/javascripts/acceptance/field-test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/javascripts/acceptance/field-test.js b/test/javascripts/acceptance/field-test.js index 918d33f0d..05bbf634b 100644 --- a/test/javascripts/acceptance/field-test.js +++ b/test/javascripts/acceptance/field-test.js @@ -336,3 +336,24 @@ acceptance("Field | Tag submission", function (needs) { ); }); }); + +acceptance("Field | Composer editor mode", function (needs) { + needs.user(); + needs.pretender((server, helper) => { + server.get("/w/wizard.json", () => helper.response(allFieldsWizard)); + }); + + test("toggles to the rich editor in one click", async function (assert) { + const toggle = ".wizard-field.composer-field .composer-toggle-switch"; + await visit("/w/wizard"); + assert.dom(toggle).hasAria("checked", "false", "starts in markdown"); + + await click(toggle); + assert.dom(toggle).hasAria("checked", "true"); + assert.dom(".wizard-field.composer-field .ProseMirror").exists(); + + await click(toggle); + assert.dom(toggle).hasAria("checked", "false"); + assert.dom(".wizard-field.composer-field textarea.d-editor-input").exists(); + }); +});