code editor: validate with cmd+enter on Mac

This commit is contained in:
jean-emmanuel 2022-02-05 14:08:28 +01:00
parent bcb74dc0b6
commit 00f116b26b
4 changed files with 8 additions and 6 deletions

View file

@ -10,6 +10,7 @@
- inspector
- color picker: inline picker widget (no longer in a modal); show color changes on the fly
- code editor: validate input with `cmd+enter` instead of `ctrl+enter` on Mac
- scripting
- `screen.height` and `screen.width` always returns the current screen dimensions

View file

@ -40,7 +40,7 @@ Selected widget's properties are displayed and can be modified in the inspector.
- Properties are written in JSON, with some flexibility brought by the [JSON5](https://github.com/json5/json5) format. For example, double quotes around object keys are not mandatory.
- Clicking on a property name spawns a help modal window
Some properties (for example `script`) have a special code editor with syntax hilighting and many keyboard shortcuts (available by clicking on the "Help" button). In this properties, pressing `enter` will not submit pending changes and instead insert a new line at the cursor position (as you would expect in a regular editor). To submit pending changes, press `ctrl+enter` or click outside the editor.
Some properties (for example `onValue`) have a special code editor with syntax hilighting and many keyboard shortcuts (available by clicking on the "Help" button). In this properties, pressing `enter` will not submit pending changes and instead insert a new line at the cursor position (as you would expect in a regular editor). To submit pending changes, press ++ctrl+enter++ (or ++cmd+enter== on Mac) or click outside the editor.
## Project tree

View file

@ -8,7 +8,8 @@ var UiModal = require('./ui-modal'),
scriptGlobals = ScriptVm.globals,
editors = {}, editorModes = {
javascript: require('brace/mode/javascript')
}
},
codeEditorModKey = (navigator.platform || '').match('Mac') ? 'Cmd' : 'Ctrl'
class CodeEditor {
@ -252,7 +253,7 @@ class CodeEditor {
<th>Command</th>
</tr>
</thead>
<tr><td><span class="kbd">Ctrl-Enter</span></td><td>save</td></tr>
<tr><td><span class="kbd">${codeEditorModKey}-Enter</span></td><td>save</td></tr>
${keybindings.map(k=>html`<tr><td><span class="kbd">${k.key}</span></td><td>${k.command}</td></tr>`)}
</table>
</div>

View file

@ -7,8 +7,8 @@ var UiWidget = require('./ui-widget'),
html = require('nanohtml'),
raw = require('nanohtml/raw'),
fastdom = require('fastdom'),
getCodeEditor = require('./ui-code-editor')
getCodeEditor = require('./ui-code-editor'),
codeEditorModKey = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey'
class UiInspector extends UiWidget {
@ -268,7 +268,7 @@ class UiInspector extends UiWidget {
if (event.keyCode === 13 &&
((!event.shiftKey && !event.target._ace) ||
(event.ctrlKey && event.target._ace))
(event[codeEditorModKey] && event.target._ace))
) {
event.preventDefault()