-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Fix and enhance comment editor monospace toggle #36181
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
base: main
Are you sure you want to change the base?
Conversation
|
I think this could be expanded to also apply the setting in other open tabs by leveraging the https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event I guess a small storage helper module is needed to abstract this out of the file and be useful for all localStorage-backed variables. |
|
I've added the bare minimum to get the setting working across tabs too. There's probably an opportunity to abstract into some |
|
|
| /** Get a setting from localStorage */ | ||
| export function getLocalStorageSetting(key: string) { | ||
| return localStorage?.getItem(key); | ||
| } | ||
|
|
||
| /** Set a setting in localStorage */ | ||
| export function setLocalStorageSetting(key: string, value: string) { | ||
| return localStorage?.setItem(key, value); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do these two wrapper functions help?
Why not just write localStorage.getItem()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrappers are in preparation to synchronize these settings with the server, e.g. the current settings would be rendered into <head> and it would trigger a POST when a setting changes. For non-logged-in users, localStorage will be continued to be used. So to support both cases, these wrappers are needed.
Maybe the functions should have a better name like getUserSetting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought this addLocalStorageChangeListener could not be implemented with server-backed storage without a websocket, I suppose. Maybe I should remove it.
| } | ||
|
|
||
| /** Apply font to the provided or all textareas on the page and optionally save on localStorage */ | ||
| function applyMonospace(enabled: boolean, {textarea, save}: {textarea?: HTMLTextAreaElement, save?: boolean}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be a method of ComboMarkdownEditor
And to change others, getComboMarkdownEditor and call their instance's method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be possible if there's a way to get references to all current ComboMarkdownEditor on the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use getComboMarkdownEditor for the related elements to get all current ComboMarkdownEditor instances
Fixes: #36175