From 2ed4bb1c8f7eb9a109f1463f768d1a1d5fe242b6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 24 Dec 2020 02:43:52 -0500 Subject: [PATCH] Ace: Config adjustments in Run JavaScript window - Use the "Chrome" theme - Hide the gutter - Don't highlight the active line - Remove default iframe borders - Focus the editor on window open Ace instances (e.g., Scaffold) are now responsible for setting their own theme (to avoid a flash of Monokai before a lighter theme appears). --- chrome/content/scaffold/scaffold.js | 6 +++++- chrome/content/zotero/ace/aceWrapper.js | 1 - chrome/content/zotero/runJS.js | 16 ++++++++++++---- chrome/skin/default/zotero/runJS.css | 6 +++++- scripts/config.js | 1 + 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/chrome/content/scaffold/scaffold.js b/chrome/content/scaffold/scaffold.js index 3c72e672e4..cbb4c2a56a 100644 --- a/chrome/content/scaffold/scaffold.js +++ b/chrome/content/scaffold/scaffold.js @@ -98,7 +98,11 @@ var Scaffold = new function() { _editors.import = importWin.editor; _editors.code = codeWin.editor; _editors.tests = testsWin.editor; - + + for (let i in _editors) { + _editors[i].setTheme('ace/theme/monokai'); + } + _editors.code.getSession().setMode(new codeWin.JavaScriptMode); _editors.code.getSession().setUseSoftTabs(false); // The first code line is preceeded by some metadata lines, such that diff --git a/chrome/content/zotero/ace/aceWrapper.js b/chrome/content/zotero/ace/aceWrapper.js index 9432d541a6..5725d3253b 100644 --- a/chrome/content/zotero/ace/aceWrapper.js +++ b/chrome/content/zotero/ace/aceWrapper.js @@ -38,5 +38,4 @@ window.addEventListener("DOMContentLoaded", function(e) { TextMode = require("ace/mode/text").Mode; EditSession = require("ace/edit_session").EditSession; editor = ace.edit('ace-div'); - editor.setTheme("ace/theme/monokai"); }, false); \ No newline at end of file diff --git a/chrome/content/zotero/runJS.js b/chrome/content/zotero/runJS.js index 1c48af1b18..a5e666adb5 100644 --- a/chrome/content/zotero/runJS.js +++ b/chrome/content/zotero/runJS.js @@ -78,15 +78,23 @@ document.getElementById('run-label').textContent = `(${shortcut})`; update(); -var codeWin, codeEditor; +var codeEditor; window.addEventListener("load", function (e) { if (e.target !== document) { return; } - codeWin = document.getElementById("editor-code").contentWindow; + var codeWin = document.getElementById("editor-code").contentWindow; codeEditor = codeWin.editor; - codeEditor.getSession().setMode(new codeWin.JavaScriptMode); - codeEditor.getSession().setUseSoftTabs(false); + var session = codeEditor.getSession(); + session.setMode(new codeWin.JavaScriptMode); + codeEditor.setOptions({ + // TODO: Enable if we modify to autocomplete from the Zotero API + //enableLiveAutocompletion: true, + highlightActiveLine: false, + showGutter: false, + theme: "ace/theme/chrome", + }); codeEditor.on('input', handleInput); + codeEditor.focus(); }, false); diff --git a/chrome/skin/default/zotero/runJS.css b/chrome/skin/default/zotero/runJS.css index 4f8cf9de4f..bd23e8a0c4 100644 --- a/chrome/skin/default/zotero/runJS.css +++ b/chrome/skin/default/zotero/runJS.css @@ -60,7 +60,11 @@ input[type=checkbox] { margin-bottom: 0; } -textarea { +iframe { + border: 1px solid gray; +} + +iframe, textarea { flex-grow: 1; margin: 5px 0; font-family: Monaco, Consolas, Inconsolata, monospace; diff --git a/scripts/config.js b/scripts/config.js index 90f098195e..4a83f74962 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -45,6 +45,7 @@ const symlinkFiles = [ 'resource/ace/keybinding-emacs.js', 'resource/ace/keybinding-vim.js', 'resource/ace/mode-javascript.js', + 'resource/ace/theme-chrome.js', 'resource/ace/theme-monokai.js', 'resource/ace/worker-javascript.js', 'update.rdf'