Skip to content

Commit

Permalink
font family select
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Jan 22, 2025
1 parent 82dc738 commit c63a9cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ <h3>Editor settings</h3>
⚠️ PASTING MODE
</label>
</p>
<p>
<label>
Font Family
<select id="settings-font-family">
<option value="monospace">monospace</option>
<option value="serif">serif</option>
</select>
</label>
</p>
</section>
<section class="development">
<h3>Development settings</h3>
Expand Down
21 changes: 16 additions & 5 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const defaultSettings = {
trackRemoteCursors: false,
welcomeMessage3: true,
pastingMode: false,
fontFamily: 'monospace',
};

const usernameInput = document.querySelector('#settings-username');
Expand All @@ -65,6 +66,7 @@ const closeBracketsCheckbox = document.querySelector('#settings-close-brackets')
const trackRemoteCursorsCheckbox = document.querySelector('#settings-track-cursors');
const welcomeMessageCheckbox = document.querySelector('#settings-welcome-message');
const pastingModeCheckbox = document.querySelector('#settings-pasting-mode');
const fontFamilySelect = document.querySelector('#settings-font-family');

function inferSettingsFromDom() {
const inferredSettings = {
Expand All @@ -84,6 +86,7 @@ function inferSettingsFromDom() {
: defaultSettings.trackRemoteCursors,
welcomeMessage3: welcomeMessageCheckbox ? welcomeMessageCheckbox.checked : defaultSettings.welcomeMessage3,
pastingMode: pastingModeCheckbox ? pastingModeCheckbox.checked : defaultSettings.pastingMode,
fontFamily: fontFamilySelect ? fontFamilySelect.value : defaultSettings.fontFamily,
};
return inferredSettings;
}
Expand All @@ -100,13 +103,16 @@ welcomeMessageCheckbox?.addEventListener('change', setSettingsFromDom);
lineWrappingCheckbox?.addEventListener('change', setSettingsFromDom);
lineNumbersCheckbox?.addEventListener('change', setSettingsFromDom);
closeBracketsCheckbox?.addEventListener('change', setSettingsFromDom);
trackRemoteCursorsCheckbox?.addEventListener('change', () => {
if (confirm('This only makes sense in boxed mode.. It also requires a reload. Are you sure?')) {
setSettingsFromDom();
window.location.reload();
}
trackRemoteCursorsCheckbox?.addEventListener('change', (e) => {
nudelConfirm(`This only makes sense in boxed mode.. It also requires a reload. Are you sure?`).then(() => {
if (confirmed) {
setSettingsFromDom();
window.location.reload();
}
});
});
pastingModeCheckbox?.addEventListener('change', setSettingsFromDom);
fontFamilySelect?.addEventListener('change', setSettingsFromDom);

let appliedSettings = null;

Expand Down Expand Up @@ -145,6 +151,7 @@ export function applySettingsToNudel(settings = getSettings()) {
welcomeMessageCheckbox.checked = settings.welcomeMessage3;
zenModeCheckbox.checked = settings.zenMode;
pastingModeCheckbox.checked = settings.pastingMode;
fontFamilySelect.value = settings.fontFamily;

session.user = settings.username || 'anonymous nudelfan';

Expand Down Expand Up @@ -216,6 +223,10 @@ export function applySettingsToNudel(settings = getSettings()) {
});
}

if (isSettingChanged('fontFamily', { previous: appliedSettings, next: settings })) {
document.documentElement.style.cssText = `--font-family: ${settings.fontFamily}`;
}

pastamirror.updateExtensions(settings, appliedSettings);

appliedSettings = { ...settings };
Expand Down
1 change: 1 addition & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ body {
.cm-scroller {
padding: 0 4px;
cursor: text;
font-family: var(--font-family) !important;
}

.cm-content {
Expand Down

0 comments on commit c63a9cd

Please sign in to comment.