Skip to content

Conversation

@silverwind
Copy link
Member

@silverwind silverwind commented Dec 17, 2025

Fixes: #36175

  1. Correctly apply setting on textareas spawned by comment edit
  2. When changing the setting, apply it to all textareas on the current page and in all other open tabs

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 17, 2025
@silverwind
Copy link
Member Author

silverwind commented Dec 17, 2025

I think this could be expanded to also apply the setting in other open tabs by leveraging the storage event:

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.

@silverwind silverwind added type/enhancement An improvement of existing functionality and removed type/bug labels Dec 17, 2025
@silverwind
Copy link
Member Author

silverwind commented Dec 17, 2025

I've added the bare minimum to get the setting working across tabs too. There's probably an opportunity to abstract into some localStorage module suitable for more similar localStorage-backed settings, but I'm not totally certain how to design it.

@silverwind silverwind changed the title Fix comment editor monospace toggle for edit mode Fix and enhance comment editor monospace toggle Dec 17, 2025
@silverwind
Copy link
Member Author

web_src/js/modules/storage.ts is now contains minimal localStorage wrapper functions and I've used them everywhere where we previously used localStorage directly (except inline scripts, but that's another topic to be solved via web components). This is in preparation so that these settings can be synced to the server in the future.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 21, 2025
Comment on lines +1 to +9
/** 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);
}
Copy link
Contributor

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()?

Copy link
Member Author

@silverwind silverwind Jan 12, 2026

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.

Copy link
Member Author

@silverwind silverwind Jan 12, 2026

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}) {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/frontend type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monospace font settings broken in comment/issue editor

4 participants