Per-user Ace theme settings

Per-user Ace theme settings

de Richard Lobb -
Número de respuestas: 2

I've been asked by a group of students to give them a 'dark' theme for the Ace editor. It does seem that dark themes are now fashionable for programming, though I'm not a huge fan myself.

I could - and perhaps should - have a CodeRunner admin setting for the Ace theme but that would be site-wide and I think this should ideally be a user preference.

The Ace editor has an obscure barely-documented keystroke Ctrl-, (i.e. CTRL + comma) that brings up a preferences menu with lots of fun options. But apart from being very obscure (I used Ace for over 10 years before accidentally typing that key combination) it's no use in CodeRunner, as the settings revert to default as soon as you click Check or navigate away, etc.

I have implemented a hack in the Ace-wrapper UI class that detects if the user has changed the theme and saves the new theme to browser local storage. When loading Ace I check for this key and switch to that theme if it's present. The theme then persists and affects all subsequent Ace editor loads. But apart from being a very obscure UI, it's also counter-intuitive that only the theme gets persisted and all the other Ace config settings revert to default. 

Ideally there would be a way for a plugin to have per-user settings but it seems from this old forum discussion that such a possibility was raised years ago but never went anywhere.

I really don't want to clutter every Ace window by adding a config-settings menu. 

Does anyone have any better ideas?

-- Richard

En respuesta a Richard Lobb

Re: Per-user Ace theme settings

de Tim Hunt -
Moodle plugins can have per-user settings. See set_user_preference in lib/moodlelib.php. The convention is to put the plugin name (qtype_coderunner) at the start of the setting name). See user_preference_allow_ajax_update for if you want to update use preferences from JavaScript code.

If you use user preferences, then technically you should add a bit in classes/privacy/provider.php

I don't think Moodle has any support for dark mode in the web application yet. Most modern browsers support prefers-color-scheme CSS selector ( / but I am not sure if that can be used to help with this situation.