code editor: keep fullscreen code editor focused and opened upon validation

This commit is contained in:
jean-emmanuel 2026-01-22 11:57:37 +01:00
parent 5bf5ab8754
commit daa4fbfecf

View file

@ -133,7 +133,6 @@ class CodeEditor {
var editor = this.editor,
input = this.input
editor.fullscreen = false
input.style.display = 'none'
input._ace_input = editor.textarea
input.tabIndex = -1
@ -141,11 +140,6 @@ class CodeEditor {
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)=>{
@ -161,27 +155,36 @@ class CodeEditor {
this.editor.dirty = true
})
setTimeout(()=>{
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)
setTimeout(()=>{
if (this.pos) {
this.editor.moveCursorTo(this.pos.row, this.pos.column)
} else {
var pos = this.editor.getCursorPosition()
if (pos.row === undefined || pos.column === undefined) {
this.editor.gotoLine(0)
}
}
this.typing = true
this.typing = 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.pos = this.editor.getCursorPosition()
this.editor.setHighlightActiveLine(false)
this.editor.setHighlightGutterLine(false)
this.editor.selection.setRange({start:0,end:0})
@ -242,13 +245,18 @@ class CodeEditor {
field.appendChild(this.helpBtn)
field.appendChild(this.fsBtn)
editor.selection.setRange({start:0,end:0})
if (this.hash !== widget.hash) {
// preserve undo history if widget is the same
editor.getSession().getUndoManager().reset()
this.hash = widget.hash
this.pos = null
} else if (editor.fullscreen) {
this.fullscreen()
}
editor.resize()
editor.resize()
}