Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions assets/javascripts/discourse/initializers/custom-wizard-edits.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -42,6 +43,34 @@ 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",

Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/javascripts/acceptance/field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading