diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js
index 7cb33c3e135..f6d800b06d1 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.js
+++ b/app/assets/javascripts/discourse/app/components/d-editor.js
@@ -50,7 +50,7 @@ let _createCallbacks = [];
class Toolbar {
constructor(opts) {
- const { site, siteSettings } = opts;
+ const { siteSettings, capabilities } = opts;
this.shortcuts = {};
this.context = null;
@@ -106,16 +106,16 @@ class Toolbar {
}),
});
- this.addButton({
- id: "code",
- group: "insertions",
- shortcut: "E",
- preventFocus: true,
- trimLeading: true,
- action: (...args) => this.context.send("formatCode", args),
- });
+ if (!capabilities.touch) {
+ this.addButton({
+ id: "code",
+ group: "insertions",
+ shortcut: "E",
+ preventFocus: true,
+ trimLeading: true,
+ action: (...args) => this.context.send("formatCode", args),
+ });
- if (!site.mobileView) {
this.addButton({
id: "bullet",
group: "extras",
@@ -354,7 +354,7 @@ export default Component.extend(TextareaTextManipulation, {
@discourseComputed()
toolbar() {
const toolbar = new Toolbar(
- this.getProperties("site", "siteSettings", "showLink")
+ this.getProperties("site", "siteSettings", "showLink", "capabilities")
);
toolbar.context = this;
@@ -708,6 +708,7 @@ export default Component.extend(TextareaTextManipulation, {
this.applySurround(selected, head, tail, exampleKey, opts),
applyList: (head, exampleKey, opts) =>
this._applyList(selected, head, exampleKey, opts),
+ formatCode: (...args) => this.send("formatCode", args),
addText: (text) => this.addText(selected, text),
getText: () => this.value,
toggleDirection: () => this._toggleDirection(),
diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js
index 14017465546..f6907fdb44f 100644
--- a/app/assets/javascripts/discourse/app/controllers/composer.js
+++ b/app/assets/javascripts/discourse/app/controllers/composer.js
@@ -332,7 +332,17 @@ export default Controller.extend({
})
);
- if (this.site.mobileView) {
+ if (this.capabilities.touch) {
+ options.push(
+ this._setupPopupMenuOption(() => {
+ return {
+ action: "applyFormatCode",
+ icon: "code",
+ label: "composer.code_title",
+ };
+ })
+ );
+
options.push(
this._setupPopupMenuOption(() => {
return {
@@ -797,6 +807,10 @@ export default Controller.extend({
});
},
+ applyFormatCode() {
+ this.toolbarEvent.formatCode();
+ },
+
applyUnorderedList() {
this.toolbarEvent.applyList("* ", "list_item");
},
diff --git a/app/assets/javascripts/discourse/app/templates/components/d-editor.hbs b/app/assets/javascripts/discourse/app/templates/components/d-editor.hbs
index eaeffe9f5c3..bba1276a65a 100644
--- a/app/assets/javascripts/discourse/app/templates/components/d-editor.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/d-editor.hbs
@@ -15,10 +15,6 @@