diff --git a/app/assets/javascripts/discourse/app/components/composer-container.hbs b/app/assets/javascripts/discourse/app/components/composer-container.hbs index ca0002889a1..8995737599f 100644 --- a/app/assets/javascripts/discourse/app/components/composer-container.hbs +++ b/app/assets/javascripts/discourse/app/components/composer-container.hbs @@ -1,6 +1,6 @@
{{#if this.composer.visible}} - {{html-class (if this.composer.showPreview "composer-has-preview")}} + {{html-class (if this.composer.isPreviewVisible "composer-has-preview")}} @@ -295,17 +295,19 @@ {{/if}} - - {{d-icon "desktop"}} - + {{#if this.composer.allowPreview}} + + {{d-icon "desktop"}} + + {{/if}} - {{#if this.composer.showPreview}} + {{#if this.composer.isPreviewVisible}} - {{#if this.site.desktopView}} + {{#if (and this.composer.allowPreview this.site.desktopView)}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.hbs b/app/assets/javascripts/discourse/app/components/composer-editor.hbs index a3ee48a7e35..4ae5c64a46b 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor.hbs +++ b/app/assets/javascripts/discourse/app/components/composer-editor.hbs @@ -30,8 +30,7 @@ @previewUpdated={{action "previewUpdated"}} @markdownOptions={{this.markdownOptions}} @extraButtons={{action "extraButtons"}} - @importQuote={{this.composer.importQuote}} - @processPreview={{this.composer.showPreview}} + @processPreview={{this.composer.isPreviewVisible}} @validation={{this.validation}} @loading={{this.composer.loading}} @forcePreview={{this.forcePreview}} diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.js index 8e76b30d93e..d2887989cf3 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor.js +++ b/app/assets/javascripts/discourse/app/components/composer-editor.js @@ -194,17 +194,29 @@ export default class ComposerEditor extends Component { this.appEvents.trigger(`${this.composerEventPrefix}:will-open`); } + /** + * Sets up the editor with the given text manipulation instance + * + * @param {TextManipulation} textManipulation The text manipulation instance + * @returns {(() => void)} destructor function + */ @bind setupEditor(textManipulation) { this.textManipulation = textManipulation; - this.uppyComposerUpload.textManipulation = textManipulation; + this.uppyComposerUpload.placeholderHandler = textManipulation.placeholder; const input = this.element.querySelector(".d-editor-input"); input.addEventListener("scroll", this._throttledSyncEditorAndPreviewScroll); - // Focus on the body unless we have a title - if (!this.get("composer.model.canEditTitle")) { + this.composer.set("allowPreview", this.textManipulation.allowPreview); + + if ( + // Focus on the editor unless we have a title + !this.get("composer.model.canEditTitle") || + // Or focus is in the body (e.g. when the editor is destroyed) + document.activeElement.tagName === "BODY" + ) { this.textManipulation.putCursorAtEnd(); } @@ -859,15 +871,6 @@ export default class ComposerEditor extends Component { @action extraButtons(toolbar) { - toolbar.addButton({ - id: "quote", - group: "fontStyles", - icon: "far-comment", - sendAction: this.composer.importQuote, - title: "composer.quote_post_title", - unshift: true, - }); - if ( this.composer.allowUpload && this.composer.uploadIcon && diff --git a/app/assets/javascripts/discourse/app/components/composer/textarea-editor.gjs b/app/assets/javascripts/discourse/app/components/composer/textarea-editor.gjs index beadea93fab..b1c635c37da 100644 --- a/app/assets/javascripts/discourse/app/components/composer/textarea-editor.gjs +++ b/app/assets/javascripts/discourse/app/components/composer/textarea-editor.gjs @@ -110,7 +110,7 @@ export default class TextareaEditor extends Component { @input={{@change}} @focusIn={{@focusIn}} @focusOut={{@focusOut}} - class="d-editor-input" + class={{@class}} @id={{@id}} {{this.registerTextarea}} /> diff --git a/app/assets/javascripts/discourse/app/components/composer/toggle-switch.gjs b/app/assets/javascripts/discourse/app/components/composer/toggle-switch.gjs new file mode 100644 index 00000000000..bc60150123a --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/composer/toggle-switch.gjs @@ -0,0 +1,47 @@ +import Component from "@glimmer/component"; +import { on } from "@ember/modifier"; +import { action } from "@ember/object"; +import concatClass from "discourse/helpers/concat-class"; +import icon from "discourse/helpers/d-icon"; + +export default class ComposerToggleSwitch extends Component { + @action + mouseDown(event) { + if (this.args.preventFocus) { + event.preventDefault(); + } + } + + +} diff --git a/app/assets/javascripts/discourse/app/components/d-editor.hbs b/app/assets/javascripts/discourse/app/components/d-editor.hbs index 27a5f94ca07..8349bd32948 100644 --- a/app/assets/javascripts/discourse/app/components/d-editor.hbs +++ b/app/assets/javascripts/discourse/app/components/d-editor.hbs @@ -8,6 +8,14 @@ {{if this.isEditorFocused 'in-focus'}}" >