keyboard: working on it

This commit is contained in:
jean-emmanuel 2022-10-29 12:37:04 +02:00
parent 3defca2a7c
commit 94ffd52215
2 changed files with 53 additions and 9 deletions

View file

@ -43,7 +43,7 @@ class OscKeybard extends UiWidget {
this.value = null
this.visible = false
this.display = html`<div class="textarea"></div>`
this.display = html`<pre class="textarea"></pre>`
this.container.appendChild(html`<div class="row">${this.display}</div>`)
this.cursor = html`<span class="cursor">|</span>`
@ -84,6 +84,19 @@ class OscKeybard extends UiWidget {
this.container.addEventListener('mousedown', (e)=>{
// prevent keyboard from stealing focus from input
e.preventDefault()
// move cursor
if (this.display.contains(e.target) && e.target !== this.display) {
var pos = DOM.index(e.target)
// adjust cursor depening on where we clicked on the letter
if (e.offsetX - DOM.offset(e.target).left >= e.target.offsetWidth / 2)
pos += 1
this.input.selectionStart = pos
if (!e.shiftKey) {
this.input.selectionEnd = pos
}
this.updateCursor()
}
}, {capture: true})
@ -150,7 +163,9 @@ class OscKeybard extends UiWidget {
this.show()
this.input = e.target
this.value = this.input.value
this.updateDisplay()
setTimeout(()=>{
this.updateDisplay()
})
}
}, {capture: true})
@ -319,10 +334,23 @@ class OscKeybard extends UiWidget {
value = this.input.osc_input ? this.input.osc_input.value :this.input.value
}
var content = html`<div class="textarea"></div>`
var content = html`<pre class="textarea"></pre>`
for (var i in value) {
let c, nl
switch (value[i]) {
case '\n':
c = raw('</br>')
nl = true
break
case ' ':
c = raw('&nbsp;')
break
default:
c = value[i]
break
}
content.appendChild(html`
<span class="${value[i] === '\n' ? 'newline' : ''}">${value[i]}</span>
<span class="${nl ? 'newline' : ''}">${c}</span>
`)
}

View file

@ -33,8 +33,9 @@ osc-keyboard {
.textarea {
height: auto;
overflow: auto;
overflow-y: auto;
width: 100%;
height: 40rem;
background: transparent;
padding: 14rem 20rem 4rem;
resize: none;
@ -44,9 +45,26 @@ osc-keyboard {
margin-top:var(---spacing);
position: relative;
pointer-events: auto;
min-height: 100%;
appearance:textarea;
cursor: text;
span {
margin: 0 0.25rem;
position: relative;
}
.newline + span:before, span:first-child:before {
content: " ";
display: block;
position: absolute;
left: -100rem;
width: 100rem;
}
.newline:before, span:last-child:before {
content: " ";
display: block;
position: absolute;
top: 0;
right: -100rem;
width: 100rem;
}
.caret {
position: relative;
@ -56,6 +74,7 @@ osc-keyboard {
box-shadow: 0 0 0 1rem var(--color-accent);
position: absolute;
animation: caret-blink 1.2s steps(2, start) infinite;
pointer-events: none;
}
}
@ -68,9 +87,6 @@ osc-keyboard {
animation: caret-blink 1.2s steps(2, start) infinite;
}
}
.newline {
display: block;
}
}
.row {