Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature in Preferences to allow user to chose the font of the page #1962

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/javascripts/app/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class app.Settings
'autoInstall'
'spaceScroll'
'spaceTimeout'
'font'
]

INTERNAL_KEYS = [
Expand Down Expand Up @@ -65,6 +66,7 @@ class app.Settings
@store.set(key, value)
delete @cache[key]
@setTheme(value) if key == 'theme'
@setFont(value) if key == 'font'
return

del: (key) ->
Expand Down Expand Up @@ -152,6 +154,11 @@ class app.Settings
@updateColorMeta()
return

setFont: (font) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing a @setFont(@get('font')) in line 141?

chosenFont = @get('font')
document.documentElement.style.setProperty('--selectedFont', chosenFont)
return

updateColorMeta: ->
color = getComputedStyle(document.documentElement).getPropertyValue('--headerBackground').trim()
$('meta[name=theme-color]').setAttribute('content', color)
Expand Down
16 changes: 15 additions & 1 deletion assets/javascripts/templates/pages/settings_tmpl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ themeOption = ({ label, value }, settings) -> """

app.templates.settingsPage = (settings) -> """
<h1 class="_lined-heading">Preferences</h1>

<div class="_settings-fieldset">
<h2 class="_settings-legend">Theme:</h2>
<div class="_settings-inputs">
Expand All @@ -20,6 +19,21 @@ app.templates.settingsPage = (settings) -> """
</div>
</div>

<div class="_settings-fieldset">
<h2 class="_settings-legend">Font:</h2>
<div class="_settings-inputs">
<label class="_settings-label _setting-font-family">
<select name="font" id="_setting-font-family">
<option value="arial" #{if (settings.font == 'Arial' or not settings.font) then ' selected' else ''}>Arial (default)</option>
<option value="cascadia" #{if settings.font == 'Cascadia' then ' selected' else ''}>Cascadia</option>
<option value="fira-code" #{if settings.font == 'Fira Code' then ' selected' else ''}>Fira Code</option>
<option value="proxima-nova" #{if settings.font == 'Proxima Nova' then ' selected' else ''}>Proxima Nova</option>
<option value="verdana" #{if settings.font == 'Verdana' then ' selected' else ''}>Verdana</option>
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the selection of the fonts. Some seem to be targetting the user interface (such as Arial). Some seem to be targetting the code blocks (such as Fira Code)?

</select>
</label>
</div>
</div>

<div class="_settings-fieldset">
<h2 class="_settings-legend">General:</h2>

Expand Down
7 changes: 7 additions & 0 deletions assets/javascripts/views/content/settings_page.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class app.views.SettingsPage extends app.View
settings.analyticsConsent = app.settings.get('analyticsConsent')
settings.spaceScroll = app.settings.get('spaceScroll')
settings.spaceTimeout = app.settings.get('spaceTimeout')
settings.font = app.settings.get('font')
settings.autoSupported = app.settings.autoSupported
settings[layout] = app.settings.hasLayout(layout) for layout in app.settings.LAYOUTS
settings
Expand All @@ -30,6 +31,10 @@ class app.views.SettingsPage extends app.View
app.settings.set('theme', value)
return

setFont: (value) ->
app.settings.set('font', value)
return

toggleLayout: (layout, enable) ->
app.settings.setLayout(layout, enable)
return
Expand Down Expand Up @@ -87,6 +92,8 @@ class app.views.SettingsPage extends app.View
switch input.name
when 'theme'
@setTheme input.value
when 'font'
@setFont input.value
when 'layout'
@toggleLayout input.value, input.checked
when 'smoothScroll'
Expand Down
6 changes: 5 additions & 1 deletion assets/stylesheets/global/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ html._theme-dark {
color-scheme: dark only;
}

:root {
--selectedFont: Arial;
}

body {
height: 100%;
margin: 0;
overflow: auto;
font-size: 1em;
font-weight: normal;
font-family: $baseFont;
font-family: var(--selectedFont, $baseFont);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In _variables.scss, we already define the variables --baseFont and --monoFont – I think we should re-use them instead of introducing another one.

line-height: 1.7;
color: $textColor; // fallback to show the error message to browsers that don't support CSS variables.
color: var(--textColor);
Expand Down
1 change: 1 addition & 0 deletions devdocs
Submodule devdocs added at 1a45f6