keybindings: more generic combo prevention in ui inputs

This commit is contained in:
jean-emmanuel 2018-08-24 13:52:23 +02:00
parent f85a3c5e74
commit 9f1c78db57
5 changed files with 16 additions and 16 deletions

View file

@ -22,7 +22,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
if (widget.props.type == 'tab' || widget.props.type == 'root') return
input = DOM.create(`<select class="input" title="${propName}"/>`)
input = DOM.create(`<select class="input no-keybinding" title="${propName}"/>`)
for (let category in widgetCategories) {
input.innerHTML += `<optgroup label="> ${category}">`
@ -42,7 +42,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
var value = typeof widget.props[propName] !== 'string' ?
JSON.stringify(widget.props[propName], null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : widget.props[propName]
input = DOM.create(`<textarea class="input" title="${propName}" rows="${value.split('\n').length}">${value}</textarea>`)
input = DOM.create(`<textarea class="input no-keybinding" title="${propName}" rows="${value.split('\n').length}">${value}</textarea>`)
DOM.addEventListener(input, ['input', 'focus'], ()=>{
input.setAttribute('rows',0)

View file

@ -48,35 +48,35 @@ var Editor = class Editor {
keyboardJS.withContext('editing', ()=>{
keyboardJS.bind('mod + z', (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.undo()
})
keyboardJS.bind(['mod + y', 'mod + shift + z'], (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.redo()
})
keyboardJS.bind('mod + c', (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.copyWidget()
})
keyboardJS.bind('mod + x', (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.cutWidget()
})
keyboardJS.bind('mod + v', (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.pasteWidget(this.mousePosition.x, this.mousePosition.y, false)
})
keyboardJS.bind('mod + shift + v', ()=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.pasteWidget(this.mousePosition.x, this.mousePosition.y, true)
})
keyboardJS.bind('delete', (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
this.deleteWidget()
})
keyboardJS.bind(['alt + up', 'alt + down', 'alt + right', 'alt + left'], (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
var deltaW = e.key === 'ArrowLeft' ? -GRIDWIDTH : e.key === 'ArrowRight' ? GRIDWIDTH : 0,
deltaH = e.key === 'ArrowUp' ? -GRIDWIDTH : e.key === 'ArrowDown' ? GRIDWIDTH : 0
@ -89,7 +89,7 @@ var Editor = class Editor {
this.resizeWidget(deltaW, deltaH)
})
keyboardJS.bind(['up', 'down', 'right', 'left'], (e)=>{
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
var deltaX = e.key === 'ArrowLeft' ? -GRIDWIDTH : e.key === 'ArrowRight' ? GRIDWIDTH : 0,
deltaY = e.key === 'ArrowUp' ? -GRIDWIDTH : e.key === 'ArrowDown' ? GRIDWIDTH : 0
@ -361,7 +361,7 @@ var Editor = class Editor {
}
mouseMove(e) {
mouseMove(e) {
this.mousePosition.x = Math.round((e.offsetX + e.target.scrollLeft) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH,
this.mousePosition.y = Math.round((e.offsetY + e.target.scrollTop) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH

View file

@ -46,7 +46,7 @@ class Dropdown extends Widget {
super({...options, html: '<div class="select"></div>'})
this.select = this.widget.appendChild(DOM.create('<select></select>'))
this.select = this.widget.appendChild(DOM.create('<select class="no-keybinding"></select>'))
this.values = []
this.keys = []

View file

@ -68,7 +68,7 @@ module.exports = class Input extends Canvas {
if (this.getProp('editable')) {
this.canvas.setAttribute('tabindex', 0)
this.canvas.addEventListener('focus', this.focus.bind(this))
this.input = DOM.create('<input></input>')
this.input = DOM.create('<input class="no-keybinding"></input>')
this.input.addEventListener('blur', (e)=>{
this.blur(false)
})

View file

@ -72,7 +72,7 @@ class Keys extends Widget {
keyDown(e) {
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
if (!this.getProp('repeat') && e) e.preventRepeat()
@ -98,7 +98,7 @@ class Keys extends Widget {
keyUp(e) {
if (e.target.classList.contains('input')) return
if (e.target.classList.contains('no-keybinding')) return
if (this.getProp('keyup') !== '') {