mirror of
https://github.com/discourse/discourse.git
synced 2025-08-17 18:04:11 +08:00
FEATURE: User preference for editor Markdown monospace font (#34051)
This commit responds to feedback in the Discourse Meta discussion https://meta.discourse.org/t/monospace-font-in-the-markdown-only-editor/359936 This change introduces a user preference that allows users to choose whether the Markdown editor uses a monospace font. The default setting is `true` for new sites, but set to `false` for existing sites to avoid disrupting current users' experiences. Admins can change the `default_other_enable_markdown_monospace_font` site setting to manage this for all users.
This commit is contained in:
parent
7a9cf9356e
commit
7121cfd4ab
27 changed files with 84 additions and 6 deletions
|
@ -65,6 +65,7 @@ export const DEFAULT_USER_PREFERENCES = [
|
|||
"default_other_dynamic_favicon",
|
||||
"default_other_like_notification_frequency",
|
||||
"default_other_skip_new_user_tips",
|
||||
"default_other_enable_markdown_monospace_font",
|
||||
"default_topics_automatic_unpin",
|
||||
"default_categories_watching",
|
||||
"default_categories_tracking",
|
||||
|
|
|
@ -4,6 +4,7 @@ import { service } from "@ember/service";
|
|||
import ItsATrap from "@discourse/itsatrap";
|
||||
import { modifier } from "ember-modifier";
|
||||
import DTextarea from "discourse/components/d-textarea";
|
||||
import concatClass from "discourse/helpers/concat-class";
|
||||
import { bind } from "discourse/lib/decorators";
|
||||
import TextareaTextManipulation from "discourse/lib/textarea-text-manipulation";
|
||||
|
||||
|
@ -110,7 +111,13 @@ export default class TextareaEditor extends Component {
|
|||
@input={{@change}}
|
||||
@focusIn={{@focusIn}}
|
||||
@focusOut={{@focusOut}}
|
||||
class={{@class}}
|
||||
class={{concatClass
|
||||
@class
|
||||
(if
|
||||
this.currentUser.user_option.enable_markdown_monospace_font
|
||||
"--markdown-monospace"
|
||||
)
|
||||
}}
|
||||
@id={{@id}}
|
||||
{{this.registerTextarea}}
|
||||
/>
|
||||
|
|
|
@ -737,10 +737,7 @@ export default class DEditor extends Component {
|
|||
<template>
|
||||
<div
|
||||
class="d-editor-container
|
||||
{{if
|
||||
this.siteSettings.rich_editor
|
||||
'd-editor-container--rich-editor-enabled'
|
||||
}}"
|
||||
{{if this.siteSettings.rich_editor '--rich-editor-enabled'}}"
|
||||
>
|
||||
<div class="d-editor-textarea-column">
|
||||
{{yield}}
|
||||
|
|
|
@ -86,6 +86,7 @@ export default class InterfaceController extends Controller {
|
|||
"dark_scheme_id",
|
||||
"bookmark_auto_delete_preference",
|
||||
"interface_color_mode",
|
||||
"enable_markdown_monospace_font",
|
||||
];
|
||||
|
||||
if (makeThemeDefault) {
|
||||
|
|
|
@ -115,6 +115,7 @@ let userOptionFields = [
|
|||
"enable_quoting",
|
||||
"enable_smart_lists",
|
||||
"enable_defer",
|
||||
"enable_markdown_monospace_font",
|
||||
"automatically_unpin_topics",
|
||||
"digest_after_minutes",
|
||||
"new_topic_duration_minutes",
|
||||
|
@ -221,6 +222,7 @@ export default class User extends RestModel.extend(Evented) {
|
|||
@userOption("external_links_in_new_tab") external_links_in_new_tab;
|
||||
@userOption("enable_quoting") enable_quoting;
|
||||
@userOption("enable_smart_lists") enable_smart_lists;
|
||||
@userOption("enable_markdown_monospace_font") enable_markdown_monospace_font;
|
||||
@userOption("dynamic_favicon") dynamic_favicon;
|
||||
@userOption("automatically_unpin_topics") automatically_unpin_topics;
|
||||
@userOption("likes_notifications_disabled") likes_notifications_disabled;
|
||||
|
|
|
@ -234,6 +234,12 @@ export default RouteTemplate(
|
|||
data-setting-name="user-dynamic-favicon"
|
||||
class="pref-dynamic-favicon"
|
||||
/>
|
||||
<PreferenceCheckbox
|
||||
@labelKey="user.enable_markdown_monospace_font"
|
||||
@checked={{@controller.model.user_option.enable_markdown_monospace_font}}
|
||||
data-setting-name="user-enable-markdown-monospace-font"
|
||||
class="pref-enable-markdown-monospace-font"
|
||||
/>
|
||||
<div
|
||||
class="controls controls-dropdown pref-page-title"
|
||||
data-setting-name="user-page-title"
|
||||
|
|
|
@ -44,6 +44,7 @@ export default {
|
|||
external_links_in_new_tab: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
dynamic_favicon: true,
|
||||
title_count_mode: "notifications",
|
||||
timezone: "Australia/Brisbane",
|
||||
|
|
|
@ -119,6 +119,7 @@ export default {
|
|||
skip_new_user_tips: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
timezone: "Australia/Brisbane",
|
||||
},
|
||||
id: 19,
|
||||
|
@ -2707,6 +2708,7 @@ export default {
|
|||
skip_new_user_tips: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
digest_after_minutes: 10080,
|
||||
automatically_unpin_topics: true,
|
||||
auto_track_topics_after_msecs: 240000,
|
||||
|
@ -3112,6 +3114,7 @@ export default {
|
|||
skip_new_user_tips: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
enable_defer: false,
|
||||
digest_after_minutes: 1440,
|
||||
automatically_unpin_topics: true,
|
||||
|
@ -3279,6 +3282,7 @@ export default {
|
|||
skip_new_user_tips: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
timezone: "Australia/Brisbane",
|
||||
},
|
||||
id: 4432,
|
||||
|
@ -3497,6 +3501,7 @@ export default {
|
|||
skip_new_user_tips: false,
|
||||
enable_quoting: true,
|
||||
enable_smart_lists: true,
|
||||
enable_markdown_monospace_font: false,
|
||||
timezone: "Australia/Brisbane",
|
||||
},
|
||||
id: 20,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
flex-grow: 1;
|
||||
max-width: 100%;
|
||||
|
||||
&--rich-editor-enabled .d-editor-textarea-wrapper textarea.d-editor-input {
|
||||
.d-editor-textarea-wrapper textarea.d-editor-input.--markdown-monospace {
|
||||
font-family: var(--d-font-family--monospace);
|
||||
font-variant-ligatures: none;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class SiteSetting < ActiveRecord::Base
|
|||
default_other_dynamic_favicon
|
||||
default_other_like_notification_frequency
|
||||
default_other_skip_new_user_tips
|
||||
default_other_enable_markdown_monospace_font
|
||||
default_topics_automatic_unpin
|
||||
default_categories_watching
|
||||
default_categories_tracking
|
||||
|
|
|
@ -84,6 +84,7 @@ class UserOption < ActiveRecord::Base
|
|||
self.enable_quoting = SiteSetting.default_other_enable_quoting
|
||||
self.enable_smart_lists = SiteSetting.default_other_enable_smart_lists
|
||||
self.enable_defer = SiteSetting.default_other_enable_defer
|
||||
self.enable_markdown_monospace_font = SiteSetting.default_other_enable_markdown_monospace_font
|
||||
self.external_links_in_new_tab = SiteSetting.default_other_external_links_in_new_tab
|
||||
self.dynamic_favicon = SiteSetting.default_other_dynamic_favicon
|
||||
self.skip_new_user_tips = SiteSetting.default_other_skip_new_user_tips
|
||||
|
@ -276,6 +277,7 @@ end
|
|||
# email_previous_replies :integer default(2), not null
|
||||
# enable_allowed_pm_users :boolean default(FALSE), not null
|
||||
# enable_defer :boolean default(FALSE), not null
|
||||
# enable_markdown_monospace_font :boolean default(TRUE), not null
|
||||
# enable_quoting :boolean default(TRUE), not null
|
||||
# enable_smart_lists :boolean default(TRUE), not null
|
||||
# external_links_in_new_tab :boolean default(FALSE), not null
|
||||
|
|
|
@ -5,6 +5,7 @@ class CurrentUserOptionSerializer < ApplicationSerializer
|
|||
:external_links_in_new_tab,
|
||||
:enable_quoting,
|
||||
:enable_smart_lists,
|
||||
:enable_markdown_monospace_font,
|
||||
:dynamic_favicon,
|
||||
:automatically_unpin_topics,
|
||||
:likes_notifications_disabled,
|
||||
|
|
|
@ -14,6 +14,7 @@ class UserOptionSerializer < ApplicationSerializer
|
|||
:enable_quoting,
|
||||
:enable_smart_lists,
|
||||
:enable_defer,
|
||||
:enable_markdown_monospace_font,
|
||||
:digest_after_minutes,
|
||||
:automatically_unpin_topics,
|
||||
:auto_track_topics_after_msecs,
|
||||
|
|
|
@ -122,6 +122,7 @@ class SiteSettingUpdateExistingUsers
|
|||
default_other_notification_level_when_replying: "notification_level_when_replying",
|
||||
default_other_like_notification_frequency: "like_notification_frequency",
|
||||
default_other_skip_new_user_tips: "skip_new_user_tips",
|
||||
default_other_enable_markdown_monospace_font: "enable_markdown_monospace_font",
|
||||
default_email_digest_frequency: "digest_after_minutes",
|
||||
default_include_tl0_in_digests: "include_tl0_in_digests",
|
||||
default_text_size: "text_size_key",
|
||||
|
|
|
@ -26,6 +26,7 @@ class UserUpdater
|
|||
enable_quoting
|
||||
enable_smart_lists
|
||||
enable_defer
|
||||
enable_markdown_monospace_font
|
||||
color_scheme_id
|
||||
dark_scheme_id
|
||||
interface_color_mode
|
||||
|
|
|
@ -1565,6 +1565,7 @@ en:
|
|||
enable_quoting: "Enable quote reply for highlighted text"
|
||||
enable_smart_lists: "Enable smart lists when writing in the composer"
|
||||
enable_defer: "Enable mark topics as unread"
|
||||
enable_markdown_monospace_font: "Use monospace font in composer's Markdown mode"
|
||||
experimental_sidebar:
|
||||
enable: "Enable sidebar"
|
||||
options: "Options"
|
||||
|
|
|
@ -2601,6 +2601,7 @@ en:
|
|||
default_other_enable_quoting: "Enable quote reply for highlighted text by default."
|
||||
default_other_enable_smart_lists: "Enable smart lists when typing in the composer by default."
|
||||
default_other_enable_defer: "Enable defer topic functionality by default."
|
||||
default_other_enable_markdown_monospace_font: "Use monospace font in composer's Markdown mode by default."
|
||||
default_other_dynamic_favicon: "Show new/updated topic count on browser icon by default."
|
||||
default_other_skip_new_user_tips: "Skip new user onboarding tips and badges."
|
||||
|
||||
|
|
|
@ -3821,6 +3821,9 @@ user_preferences:
|
|||
default: 1
|
||||
enum: "CompositionModeSiteSetting"
|
||||
area: "posts_and_topics|user_defaults"
|
||||
default_other_enable_markdown_monospace_font:
|
||||
default: true
|
||||
area: "posts_and_topics|user_defaults"
|
||||
|
||||
api:
|
||||
retain_web_hook_events_period_days:
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
class EnableMarkdownMonospaceFontUserOption < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_column :user_options, :enable_markdown_monospace_font, :boolean, default: true, null: false
|
||||
|
||||
if Migration::Helpers.existing_site?
|
||||
execute <<~SQL
|
||||
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
||||
VALUES('default_other_enable_markdown_monospace_font', 5, 'f', NOW(), NOW())
|
||||
ON CONFLICT (name) DO NOTHING
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE user_options
|
||||
SET enable_markdown_monospace_font = false
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
if column_exists?(:user_options, :enable_markdown_monospace_font)
|
||||
remove_column :user_options, :enable_markdown_monospace_font
|
||||
end
|
||||
|
||||
execute <<~SQL if Migration::Helpers.existing_site?
|
||||
DELETE FROM site_settings WHERE name = 'default_other_enable_markdown_monospace_font'
|
||||
SQL
|
||||
end
|
||||
end
|
|
@ -191,6 +191,7 @@ def insert_user_options
|
|||
automatically_unpin_topics,
|
||||
enable_quoting,
|
||||
enable_smart_lists,
|
||||
enable_markdown_monospace_font,
|
||||
external_links_in_new_tab,
|
||||
dynamic_favicon,
|
||||
new_topic_duration_minutes,
|
||||
|
@ -220,6 +221,7 @@ def insert_user_options
|
|||
, #{SiteSetting.default_other_enable_smart_lists}
|
||||
, #{SiteSetting.default_other_external_links_in_new_tab}
|
||||
, #{SiteSetting.default_other_dynamic_favicon}
|
||||
, #{SiteSetting.default_other_enable_markdown_monospace_font}
|
||||
, #{SiteSetting.default_other_new_topic_duration_minutes}
|
||||
, #{SiteSetting.default_other_auto_track_topics_after_msecs}
|
||||
, #{SiteSetting.default_other_notification_level_when_replying}
|
||||
|
|
|
@ -180,6 +180,7 @@ CREATE TABLE user_options
|
|||
email_previous_replies INTEGER,
|
||||
enable_allowed_pm_users BOOLEAN,
|
||||
enable_defer BOOLEAN,
|
||||
enable_markdown_monospace_font BOOLEAN,
|
||||
enable_quoting BOOLEAN,
|
||||
enable_smart_lists BOOLEAN,
|
||||
external_links_in_new_tab BOOLEAN,
|
||||
|
|
|
@ -50,6 +50,7 @@ module Migrations::Converters::Discourse
|
|||
enable_defer: item[:enable_defer],
|
||||
enable_quoting: item[:enable_quoting],
|
||||
enable_smart_lists: item[:enable_smart_lists],
|
||||
enable_markdown_monospace_font: item[:enable_markdown_monospace_font],
|
||||
external_links_in_new_tab: item[:external_links_in_new_tab],
|
||||
hide_presence: item[:hide_presence],
|
||||
hide_profile: item[:hide_profile],
|
||||
|
|
|
@ -40,6 +40,7 @@ module Migrations::Database::IntermediateDB
|
|||
enable_defer,
|
||||
enable_quoting,
|
||||
enable_smart_lists,
|
||||
enable_markdown_monospace_font,
|
||||
external_links_in_new_tab,
|
||||
hide_presence,
|
||||
hide_profile,
|
||||
|
@ -111,6 +112,7 @@ module Migrations::Database::IntermediateDB
|
|||
enable_defer: nil,
|
||||
enable_quoting: nil,
|
||||
enable_smart_lists: nil,
|
||||
enable_markdown_monospace_font: nil,
|
||||
external_links_in_new_tab: nil,
|
||||
hide_presence: nil,
|
||||
hide_profile: nil,
|
||||
|
@ -176,6 +178,7 @@ module Migrations::Database::IntermediateDB
|
|||
::Migrations::Database.format_boolean(enable_defer),
|
||||
::Migrations::Database.format_boolean(enable_quoting),
|
||||
::Migrations::Database.format_boolean(enable_smart_lists),
|
||||
::Migrations::Database.format_boolean(enable_markdown_monospace_font),
|
||||
::Migrations::Database.format_boolean(external_links_in_new_tab),
|
||||
::Migrations::Database.format_boolean(hide_presence),
|
||||
::Migrations::Database.format_boolean(hide_profile),
|
||||
|
|
|
@ -607,6 +607,7 @@ class BulkImport::Base
|
|||
automatically_unpin_topics
|
||||
enable_quoting
|
||||
enable_smart_lists
|
||||
enable_markdown_monospace_font
|
||||
external_links_in_new_tab
|
||||
dynamic_favicon
|
||||
new_topic_duration_minutes
|
||||
|
@ -1394,6 +1395,7 @@ class BulkImport::Base
|
|||
automatically_unpin_topics: SiteSetting.default_topics_automatic_unpin,
|
||||
enable_quoting: SiteSetting.default_other_enable_quoting,
|
||||
enable_smart_lists: SiteSetting.default_other_enable_smart_lists,
|
||||
enable_markdown_monospace_font: SiteSetting.default_other_enable_markdown_monospace_font,
|
||||
external_links_in_new_tab: SiteSetting.default_other_external_links_in_new_tab,
|
||||
dynamic_favicon: SiteSetting.default_other_dynamic_favicon,
|
||||
new_topic_duration_minutes: SiteSetting.default_other_new_topic_duration_minutes,
|
||||
|
|
|
@ -81,6 +81,7 @@ RSpec.describe UserOption do
|
|||
it "should apply defaults from site settings" do
|
||||
SiteSetting.default_other_enable_quoting = false
|
||||
SiteSetting.default_other_enable_smart_lists = false
|
||||
SiteSetting.default_other_enable_markdown_monospace_font = false
|
||||
SiteSetting.default_other_enable_defer = true
|
||||
SiteSetting.default_other_external_links_in_new_tab = true
|
||||
SiteSetting.default_other_dynamic_favicon = true
|
||||
|
@ -90,6 +91,7 @@ RSpec.describe UserOption do
|
|||
|
||||
expect(user.user_option.enable_quoting).to eq(false)
|
||||
expect(user.user_option.enable_smart_lists).to eq(false)
|
||||
expect(user.user_option.enable_markdown_monospace_font).to eq(false)
|
||||
expect(user.user_option.enable_defer).to eq(true)
|
||||
expect(user.user_option.external_links_in_new_tab).to eq(true)
|
||||
expect(user.user_option.dynamic_favicon).to eq(true)
|
||||
|
|
|
@ -2180,6 +2180,7 @@ RSpec.describe User do
|
|||
SiteSetting.default_other_enable_smart_lists = false
|
||||
SiteSetting.default_other_dynamic_favicon = true
|
||||
SiteSetting.default_other_skip_new_user_tips = true
|
||||
SiteSetting.default_other_enable_markdown_monospace_font = false
|
||||
|
||||
SiteSetting.default_hide_profile = true
|
||||
SiteSetting.default_hide_presence = true
|
||||
|
@ -2202,6 +2203,7 @@ RSpec.describe User do
|
|||
expect(options.external_links_in_new_tab).to eq(true)
|
||||
expect(options.enable_quoting).to eq(false)
|
||||
expect(options.enable_smart_lists).to eq(false)
|
||||
expect(options.enable_markdown_monospace_font).to eq(false)
|
||||
expect(options.dynamic_favicon).to eq(true)
|
||||
expect(options.skip_new_user_tips).to eq(true)
|
||||
expect(options.hide_profile).to eq(true)
|
||||
|
|
|
@ -717,6 +717,9 @@
|
|||
"enable_smart_lists": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable_markdown_monospace_font": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable_defer": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
@ -836,6 +839,7 @@
|
|||
"dynamic_favicon",
|
||||
"enable_quoting",
|
||||
"enable_smart_lists",
|
||||
"enable_markdown_monospace_font",
|
||||
"enable_defer",
|
||||
"digest_after_minutes",
|
||||
"automatically_unpin_topics",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue