Adding option to set default options for Ace editor
-
Hello, this is a terrific plugin – best file manager I’ve seen so far!
I notice that there is a UI interface / sidebar to modify options for the Ace editor, but there is no way to save those as a default, nor could I set the defaults for each new editor that opens in a config file…
I’ve created and tested code in my local that allows this to be set, using JSON files to configure the default configuration options for each Ace Editor instance that Filester creates…
There is likely a better way, so i welcome feedback, but here is my working code, so far:
At line 970 in:
/plugins/filester/includes/File_manager/lib/js/extras/editors.default.js
After this existing code:
editor.setOptions({ theme: 'ace/theme/monokai', fontSize: '14px', wrap: true, });
…add this chunk here:
// load a custom config JSON file if it exists var request = new XMLHttpRequest(); request.open("GET", "/.ace_config_default.json", false); request.send(null) if (request.responseText.indexOf("{") === 0) { // console.log('editor options', Object.keys(editor.$options)); editor.setOptions(JSON.parse(request.responseText)); }
Then, create a new file in your web root, named:
.ace_config_default.json
– then, after Fliester loads a file in the Ace Editor, the settings in the json file will set the options for the new editor instance.See options here: listed in this doc here
Then, if you want to set a configuration for each separate file mode…
In the same file, further down, after this code chunk here:
editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: false });
Add this next chunk:
// load a custom config JSON file for the current mode var request = new XMLHttpRequest(); request.open("GET", "/.ace_config_" + editor.getOption('mode').substring(editor.getOption('mode').lastIndexOf('/') + 1) + ".json", false); request.send(null) if (request.responseText.indexOf("{") === 0) { // console.log(editor.getOption('mode') + ' options', Object.keys(editor.$options)); editor.setOptions(JSON.parse(request.responseText)); }
Once that is in place, you can create JSON files in the web root to configure the settings for the editor, for each of the different file types, for example:
– .ace_config_default.json // for all editors
– .ace_config_scss.json
– .ace_config_php.json
– .ace_config_javascript.jsonetc…
Here is a sample of the contents of my default configuration JSON file:
{ "fontSize": "11px", "wrap": true, "highlightActiveLine": true, "highlightSelectedWord": true, "showPrintMargin": false, "scrollPastEnd": "0.5", "cursorStyle": "wide", "keyboardHandler": "ace/keyboard/vscode", "enableMultiselect": true, "enableBlockSelect": true }
How do I properly submit a pull request to have this considered for core, please?
I don’t use SVN yet, but if I have to learn I can. I couldn’t find the codebase on Github…
Sidenote : When will the WP team finally move to Git. **~sigh~** SVN is soooo….1990’s ??
- The topic ‘Adding option to set default options for Ace editor’ is closed to new replies.