editor: proper tab navigation in inspector + keyboard category fold/unfold with enter/space when focused
editor: add mod + f to focus tree search code editor: fix nasty bug when focusing field using tab key editor: f2 focuses "html" property when "label" is not present
This commit is contained in:
parent
1c984a57e0
commit
89b8daa35a
7 changed files with 67 additions and 19 deletions
|
|
@ -14,6 +14,15 @@ var UiModal = require('./ui-modal'),
|
|||
|
||||
ace.config.set('basePath', '/client/workers/')
|
||||
|
||||
function setCommandEnabled(editor, name, enabled) {
|
||||
var command = editor.commands.byName[name]
|
||||
if (!command.bindKeyOriginal)
|
||||
command.bindKeyOriginal = command.bindKey
|
||||
command.bindKey = enabled ? command.bindKeyOriginal : null
|
||||
editor.commands.addCommand(command)
|
||||
}
|
||||
|
||||
|
||||
class CodeEditor {
|
||||
|
||||
constructor(parent, name, language, syntaxChecker) {
|
||||
|
|
@ -119,25 +128,47 @@ class CodeEditor {
|
|||
editor.fullscreen = false
|
||||
input.style.display = 'none'
|
||||
input._ace_input = editor.textarea
|
||||
input.tabIndex = -1
|
||||
|
||||
editor.setValue(input.value)
|
||||
editor.textarea.osc_input = input
|
||||
editor.textarea.tabIndex = 0
|
||||
editor.selection.setRange({start:0,end:0})
|
||||
if (!this.widget || widget.hash !== this.widget.hash) {
|
||||
// preserve active line if widget is the same
|
||||
editor.gotoLine(0)
|
||||
}
|
||||
|
||||
editor.removeAllListeners('focus')
|
||||
this.editor.on('focus', (e)=>{
|
||||
this.parent.focusedInput = this.input
|
||||
this.editor.setHighlightActiveLine(true)
|
||||
this.editor.setHighlightGutterLine(true)
|
||||
|
||||
this.editor.removeAllListeners('blur')
|
||||
this.editor.removeAllListeners('change')
|
||||
this.editor.removeAllListeners('changeSelection')
|
||||
this.editor.on('change', (e)=>{
|
||||
this.input.value = this.editor.getValue()
|
||||
// this.parent.focusedInput = this.input
|
||||
this.editor.dirty = true
|
||||
})
|
||||
|
||||
var pos = this.editor.getCursorPosition()
|
||||
if (pos.row === undefined || pos.column === undefined) this.editor.gotoLine(0)
|
||||
|
||||
this.typing = false
|
||||
setCommandEnabled(this.editor, "indent", false)
|
||||
setCommandEnabled(this.editor, "outdent", false)
|
||||
|
||||
this.editor.on('changeSelection', ()=>{
|
||||
if (this.typing) return
|
||||
let pos = this.editor.getCursorPosition()
|
||||
if (pos.row || pos.column) {
|
||||
setCommandEnabled(this.editor, "indent", true)
|
||||
setCommandEnabled(this.editor, "outdent", true)
|
||||
}
|
||||
this.typing = true
|
||||
})
|
||||
this.editor.on('blur', (e)=>{
|
||||
this.editor.setHighlightActiveLine(false)
|
||||
this.editor.setHighlightGutterLine(false)
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ class UiInspectorField extends UiWidget {
|
|||
|
||||
if (this.widget.props.type == 'tab' || this.widget.props.type == 'root') {
|
||||
this.container.appendChild(html`
|
||||
<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
|
||||
<textarea tabIndex="0" class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
|
||||
`)
|
||||
return
|
||||
}
|
||||
|
||||
this.createInput()
|
||||
|
||||
var select = html`<select tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}"/>`
|
||||
var select = html`<select tabIndex="-1" class="no-keybinding" name="${this.name}"/>`
|
||||
|
||||
for (let cname in categories) {
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ class UiInspectorField extends UiWidget {
|
|||
JSON.stringify(this.value, null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : this.value
|
||||
|
||||
|
||||
let input = html`<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}"></textarea>`
|
||||
let input = html`<textarea tabIndex="0" class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}"></textarea>`
|
||||
|
||||
if (this.name === 'id' && this.widget.props.type === 'root') input.disabled = true
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ class UiInspectorField extends UiWidget {
|
|||
if (this.default.choices) {
|
||||
|
||||
let wrapper = html`<osc-inspector-select></osc-inspector-select>`,
|
||||
select = wrapper.appendChild(html`<select class="no-keybinding" name="${this.name}"/>`)
|
||||
select = wrapper.appendChild(html`<select tabIndex="-1" class="no-keybinding" name="${this.name}"/>`)
|
||||
for (let choice of this.default.choices) {
|
||||
select.appendChild(html`<option ${choice == this.value ? 'selected' : ''} value="${choice}">${choice}</option>`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@ class UiInspector extends UiWidget {
|
|||
var widget = widgets[0],
|
||||
lock = widgets.some(w=>w.getProp('lock')),
|
||||
props = defaults[widget.props.type],
|
||||
tabIndex = 1000,
|
||||
codeEditorFields = []
|
||||
|
||||
this.widget = widget
|
||||
|
|
@ -202,7 +201,7 @@ class UiInspector extends UiWidget {
|
|||
if (widgets.length > 1 && categoryName === 'class_specific') categoryLabel = 'shared properties'
|
||||
|
||||
category.appendChild(html`
|
||||
<div class="category-header" data-name="${categoryName}">${categoryLabel}${categoryName === 'widget' && widgets.length > 1 ? `s (${widgets.length})` : ''}</div>
|
||||
<div class="category-header" tabIndex="0" data-name="${categoryName}">${categoryLabel}${categoryName === 'widget' && widgets.length > 1 ? `s (${widgets.length})` : ''}</div>
|
||||
`)
|
||||
|
||||
let notEmpty
|
||||
|
|
@ -235,7 +234,6 @@ class UiInspector extends UiWidget {
|
|||
name: propName,
|
||||
value: widget.props[propName],
|
||||
default: def,
|
||||
tabIndex: tabIndex++
|
||||
}).container
|
||||
if (first) field.classList.add('first-child')
|
||||
|
||||
|
|
@ -346,6 +344,11 @@ class UiInspector extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
} else if ((event.key == 'Enter' || event.key == ' ') && event.target.classList.contains('category-header')) {
|
||||
|
||||
event.preventDefault()
|
||||
DOM.dispatchEvent(event.target, 'fast-click', {})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue